• ALGEMENE VOORWAARDEN
  • GENERAL TERMS & CONDITIONS

KUDOS - IT consultant and FOSS supporter

  • home
  • contact
  • services
  • baanboard
  • msx
Home

Feed aggregator

+= operator

UNIX.com - Mon, 06/09/2010 - 03:42
im new to bash scripting and im just using online tutorials and trial and error. i wanted to write a script to read numbers from a file and find their sum:



Code: #!/bin/bash

theSum=0
for line in $(cat numbers.txt)
do
        let "theSum = theSum + $line"
        echo "$line"
done

echo "The sum is $theSum"


when i run this it echoes all the numbers but doesnt give me the correct sum and echo $? returns 0. my console output looks like this:

Code: $ ./test.sh
")syntax error: invalid arithmetic operator (error token is "
1
")syntax error: invalid arithmetic operator (error token is "
2
")syntax error: invalid arithmetic operator (error token is "
34
")syntax error: invalid arithmetic operator (error token is "
77
89
The sum is 89
im not sure why i am getting those syntax errors. thanks.

Replace and retain entries.

UNIX.com - Mon, 06/09/2010 - 03:34
Replace and retain entries.
I have a certain users that will replaced a certain values, but if it has already a value it will retain its values.
Thanks



Data to be placed:
account_locked = false
loginretries = 0
pwdwarntime = 0
histsize = 0
minalpha = 0
minother = 0
minlen = 0
maxage = 0
minage = 0

SAMPLE:
cat /etc/security/user
Original:
oracle9i:
SYSTEM = "NONE"
admin = false
histsize = 0
minalpha = 0
minlen = 1

Output:
oracle9i:
SYSTEM = "NONE"
admin = false
histsize = 0
minalpha = 0
minlen = 0
account_locked = false
loginretries = 0
pwdwarntime = 0
maxage = 0
minage = 0
minother = 0

how to format a number in bash

UNIX.com - Mon, 06/09/2010 - 02:09
Say I have a number x=123, but I want to it be x=000123, because I need to use it in as a file name. thanks!

how to format a numbr in bash

UNIX.com - Mon, 06/09/2010 - 02:09
Say I have a number x=123, but I want to it be x=000123, because I need to use it in as a file name. thanks!

I need a reply

UNIX.com - Mon, 06/09/2010 - 01:39
What command can you use to display a text file one page at a time, but doesn't allow scrolling backward through a file?

Question on awk for finding the column number using a match word

UNIX.com - Mon, 06/09/2010 - 00:40
Hi Guys,

Please help me out in my situation of writing a shell script

Exampl:I have a output like

asnapply 1 2 3 apply_server=1 apply_schema=ASN
asnapply 1 2 3 apply_server=2 apply_schema=ASN

Now i need output like
asnacmd applysever=1 applyschema=ASN stop
asnacmd applysever=2 applyschema=ASN stop

I tried awk but hardcoded and printed but i have a question instead of hardcoding the column number,how can i get the column number matching apply_server from input and print apply_server=1

Any help appreciated
Thanks

Remove LAN Manager Client (LMC)

UNIX.com - Sun, 05/09/2010 - 22:14
hi

During startup of SCO 5.0.6 I'm getting this message below.
Howto remove or disable LAN Manager Client (LMC) from startup?
Attached Images lmc.GIF (3.6 KB)

Green IT

UNIX.com - Sun, 05/09/2010 - 21:45
2010-09-05T21:33:57+02:00






Tweet




Source...

Gauss Shape in gnuplot

UNIX.com - Sun, 05/09/2010 - 21:37
I have been looking in different documentations for gnuplot, I am trying to plot a gauss shape over my histogram ( a plot I made in gnuplot w 'boxes') ... I can't find anything helpful any recommendations on how to do it or where to find help?

Thanks!

---------- Post updated 09-05-10 at 03:37 PM ---------- Previous update was 09-04-10 at 07:24 PM ----------

Does my question make sense? Is it a trivial question? I still can't find an answer :( I can explain it in more details and send the histogram file if that helps... I'm really stuck :(

expr command to extract words

UNIX.com - Sun, 05/09/2010 - 21:25
how to use expr command to retrieve all the words before the equal sign "=" with shell script

A Peek Behind the Curtain of the Texas Antitrust Complaints against Google

UNIX.com - Sun, 05/09/2010 - 20:45
I guess you heard that the Texas attorney general has opened an investigation into antitrust complaints against Google, complaints lodged by Foundem, SourceTool, and myTriggers.com. Them again? Their complaints are not new. Here's Google's blog post about it.
And likely you heard about that utterly tasteless ad in Times Square from Consumer Watchdog, a cartoon of a creepy looking Eric Schmidt handing ice cream to children and asking for their secrets.
I think I can explain both events, because they are part of one campaign. Or as American Lawyer describes [PDF] the lawyers behind this, they are on a crusade against Google. The article is titled "The Google-Slayers". Guess who the lawyers on this crusade have as a client? Microsoft. They handle Microsoft's antitrust work. Guess who sent the first complainant to these lawyers, which led to this crusade? Microsoft. The jumping off point.
So. A crusade to destroy Google. By folks who count Microsoft as an important client, with new clients, at least one of them directly referred to the "crusaders" by Microsoft and the rest now under their umbrella. My stars, gentlemen. Where is your subtlety?
But there's more.

More...

Problem using function in awk

UNIX.com - Sun, 05/09/2010 - 20:36
I created two functions that output two random variables. I want to output them in the output file. But it does not seem to work.

Code: # Function rgaussian1(r1, r2)
# Gaussian random number generator
  function rgaussian1(r1, r2) {
      pi = 3.142
      v1 = sqrt( -2 * log(rand()) )
      v2 = 2 * pi * rand()
      r1 = a * sin(b)
      r2 = a * cos(b)
  }

# Function rgaussian2(r1, r2)
# Gaussian random number generator
  function rgaussian2(r1, r2) {

      do {
          v1 = 2 * rand() - 1
          v2 = 2 * rand() - 1
          rsq = v1 * v1 + v2 * v2
      } while (rsq > 1)

      fac = sqrt(-2 * log(rsq) / rsq)
      r1 = v2 * fac
      r2 = v1 * fac

  }

# Include gaussian distributed random numbers
  NF == 2 {
      rgaussian1(r1, r2)
      rgaussian2(r3, r4)
      print $0,$2,r1,r2,r3,r4
  }

non blocking connect

UNIX.com - Sun, 05/09/2010 - 20:15
OS : solaris 10 X86

I created stream socket, tries to connect to port 7 on the remote machine.
After doing the non blocking connect call I did select with time out value is 3 secs. I am always getting timed out though I am writing prior to select.

code:

Code: x=fcntl(S,F_GETFL,0);
fcntl(s,F_SETFL,x | O_NONBLOCK);
rc=connect(s, (struct sockaddr *)&sin, sizeof(sin));
if( rc == 0)
  write(s,"service",7);
else
{
  if( errno == EINPROGRESS)
  {
        write(s,"service",7);
    FD_ZERO(&writeFDs);
    FD_SET(s, &writeFDs);
    rc=select(maxFDs, &writeFDs, (fd_set *) NULL, (fd_set *)NULL,
                                                                (struct timeval *)(&timeout));
    if( rc ==0 || rc == -1)
      printf(" Timed out -- Not connected even after 3 secs wait");
    else
      printf(" connected and written");
} My doubt is write on non blocking socket will happen or write fails and select will timeout. What do I have to do to connection successful

Moderator's Comments: After more than 40 posts you should know how and when to apply code tags

---------- Post updated 09-05-10 at 01:11 PM ---------- Previous update was 09-04-10 at 11:56 PM ----------

I found wrong in my code. I should move my write to the else part and I should set read flags as NULL and write flags as my socket.

---------- Post updated at 01:15 PM ---------- Previous update was at 01:11 PM ----------

my code should be

Code: if( errno == EINPROGRESS)
{       
    FD_ZERO(&writeFDs);
    FD_SET(s, &writeFDs);
    rc=select(maxFDs, (fd_set *) NULL, &writeFDs,  (fd_set *)NULL,
                                                                (struct timeval *)(&timeout));
    if( rc ==0 || rc == -1)
      printf(" Timed out -- Not connected even after 3 secs wait");
    else
      write(s,"service",7);

Delete lines after semicolon

UNIX.com - Sun, 05/09/2010 - 19:56
Code: char str[MAX]; char str [MAX];
char *ptr; char * ptr;
int CASE; int CASE;
double temp; double temp; Output should be:
Code: char str[MAX];
char *ptr;
int CASE;
double temp; How can i do this with awk,sed,perl?

Generating Gaussian Distributed Random Numbers

UNIX.com - Sun, 05/09/2010 - 19:46
I want to generate an awk function that generated a Gaussian distributed set of random numbers. I need to implement the thing below in awk. Rnd is just a uniform random number between 0 and 1

Code:   function rgaussian(r1, r2) {
      Do
          v1 = 2 * Rnd - 1
          v2 = 2 * Rnd - 1
          rsq = v1 * v1 + v2 * v2
      Loop Until rsq <= 1

      fac = Sqr(-2 * Log(rsq) / rsq)
      r1 = v2 * fac
      r2 = v1 * fac
  }

adding a line to file

UNIX.com - Sun, 05/09/2010 - 19:30
i am writing a script which will let user to input a line.
i m not sure how do i add this line to the end of a txt file ?

how do i access db2instance via telnet command prompt

UNIX.com - Sun, 05/09/2010 - 19:16
Hi
I have a perl script code in which connecting with db2 database and doing some process. My perl script code and db2 database server present in the same unix server. I am connecting and executing perl script code via windows telnet. Now my question is i could not able to connect db2 server or invoke my db2 instance..If i give any db2 commands via telnet it's giving command not found. I wanted to invoke db2 instance via telnet through perl script.any help?

thanks in advance..

Solaris- VxVM simulator

UNIX.com - Sun, 05/09/2010 - 19:13
Hi,

Could any one tel me VxVM simulator is available in market or can it be downloaded from any were????

How do i access sybase using isql and how do i get result set in perl script?

UNIX.com - Sun, 05/09/2010 - 19:05
Hi,

How do i get result set in perl script using isql while connecting sybase server.
I have a perl script which connected to sybase and get the result set. but i wanted to get the result set. How do i get the result set in perl script not unix shell script..

Code: $server ="ServerName";

open ISQL, "| isql -H hostname -U sa -P\"\" -S $server -D master " or die "Failed to open: $!";
print ISQL<< "EOF";
select srvname,srvid from sysservers
go
quit
EOF any help really appreciated.. thanks in advance..

bash script + php

UNIX.com - Sun, 05/09/2010 - 18:10
Hello,
I want to move some of my bash scripts to php ( add samba user, add new PC in dhcp and etc. ).With Google, I found some articles for bash and php, but there is only simple examples, nothing for variables.
Example:

Code: #!/bin/bash
status=`/usr/local/etc/rc.d/isc-dhcpd status`
############
echo -n "Enter hostname: "
read host
echo -n "Enter MAC: "
read mac
echo -n "Enter IP: "
read ip
echo -n "Restart dhcp(y/n): "
read dhcp
echo "host $host { " >> dhcpd.conf
echo "hardware ethernet $mac;" >> dhcpd.conf
echo "fixed-address $ip;" >> dhcpd.conf
echo "}" >> dhcpd.conf
if [ $dhcp = y ];then
echo "/usr/local/etc/rc.d/isc-dhcpd restart"
echo "$status"
else
echo "Done"
fi So I want to have a php field for $host, field for $mac and field for $ip.
Is there some articles or examples for this?
I have some php shells, but they are full with s*its.I wana to learn something.
Thanks
  • « first
  • ‹ previous
  • …
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • …
  • next ›
  • last »
Syndicate content

Navigation

  • Glossary
  • Recent posts

Search

User login

  • Request new password

Recent comments

  • reply this post
    1 week 5 days ago
  • answer
    2 weeks 1 day ago
  • On the same port
    14 weeks 1 day ago
  • All, with 2 daemons running
    17 weeks 3 days ago
  • /etc/init.d/sshd
    21 weeks 4 days ago
  • No easy way to do this
    21 weeks 5 days ago
  • external iface is dhcpd addressed
    21 weeks 5 days ago
  • Great
    23 weeks 6 days ago
  • Great!
    26 weeks 6 days ago
  • Thanks!
    28 weeks 5 days ago

Use Free Software!

Visit the Free Software Directory

Baanboard.com

  • Logname not authorised
  • Infor Tools Consultants
  • Infor Distribution Consultants
  • Tipo de Font
  • To Display details of an Order in the special menu
more

UNIX.com

  • using awk to print absolute value
  • How to write to .csv file
  • Distribution Release: Linux Mint 201009 "Debian"
  • Help on "tr' command
  • Mapping with series from master file and calculate count
more

  • home
  • contact
  • services
  • baanboard
  • msx