| Author |
Message |
ankit12345
Joined: 27 Dec 2005 Posts: 299 Helped: 5 Location: bangalore,India
|
20 Feb 2007 13:55 simple script |
|
|
|
Im new to linux.....
I want to write a shell script .......what i did is........
-------------------------------------
#!/bin/bash
echo "some directory num"
read number
echo "$number"
if [ $number = 1] then
cd /proj/caupaxg/cx_modsim/cx_xmac
else
cd /jhsd/kJSAD/SKJ
fi
pwd
---------------------------------------
if i did source......read command failed...........
if i ran directly using the file name.....cd command failed..........
Spent some time in google.....but failed to find the sol......plzz help me.....
|
|
| Back to top |
|
 |
nafraf
Joined: 02 May 2002 Posts: 66 Helped: 2
|
03 Mar 2007 1:13 Re: simple script |
|
|
|
It works for me...
| Code: |
#!/bin/bash
echo "some directory num"
read number
echo "$number"
if [ $number = 1 ]; then
cd ~/tmp/dir1
else
cd ~/tmp/dir2
fi
pwd |
|
|
| Back to top |
|
 |
pakitos
Joined: 14 Nov 2005 Posts: 318 Helped: 38
|
05 Mar 2007 14:56 Re: simple script |
|
|
|
The thing you are doing is easy and straight forward it should work!!
what is your problem?
what do you want to do?
|
|
| Back to top |
|
 |
synpscrk
Joined: 24 Oct 2004 Posts: 15
|
06 Mar 2007 9:17 Re: simple script |
|
|
|
| Read some book
|
|
| Back to top |
|
 |
gtm56
Joined: 01 May 2008 Posts: 3
|
01 May 2008 10:52 Re: simple script |
|
|
|
Hi all,
I'm having a problem with a simple script i'm trying to create.
I have created a file that has this form:
| Code: |
2 xx.xxx.xxx.xx
1 xxx.xxx.xxx.xx
1 xxx.xxx.xxx.xx
|
*the ips have been replaced with 'x'
Now i want to detect if any number from the first column is above a certain limit.
The problem is that when i use awk to check the first argument in the line it can't be recognised.This is where i need some help.
After the detection i'll do some actions with the ip that refers to the number that has been detected to be higher than the limit.
thanks.
|
|
| Back to top |
|
 |
meitolake
Joined: 07 Oct 2007 Posts: 143 Helped: 23 Location: China
|
02 May 2008 2:01 simple script |
|
|
|
| Can you show your code?
|
|
| Back to top |
|
 |
gtm56
Joined: 01 May 2008 Posts: 3
|
03 May 2008 11:41 Re: simple script |
|
|
|
Here is what i want to do.
The file is created using the netstat command.The problem is that i want to compare only the first column with the variable limit.
| Code: |
#!/bin/bash -x
limit=4
netstat -tanp | grep \:80 | awk '{print $5}' | cut -f 1 -d: | sort | uniq -c | sort -nr | head -n 20 > test;
chmod +x test
for i in `cat /home/...../test`
do
if [ $limit -lt $i ] then
echo found
fi
done
|
|
|
| Back to top |
|
 |
meitolake
Joined: 07 Oct 2007 Posts: 143 Helped: 23 Location: China
|
04 May 2008 5:09 Re: simple script |
|
|
|
I have modified your script.
| Code: |
#!/bin/bash -x
limit=4
netstat -tanp | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | \
uniq -c | sort -nr | head -n 20 >/tmp/test$$
chmod +x /tmp/test$$
for i in `cat /tmp/test$$`; do
if [ $limit -lt $i ]; then
echo found
fi
done
|
Last edited by meitolake on 05 May 2008 3:01; edited 1 time in total |
|
| Back to top |
|
 |
gtm56
Joined: 01 May 2008 Posts: 3
|
04 May 2008 18:33 Re: simple script |
|
|
|
Thanks for the modification.
The problem is that something is wrong with i.
If you try this
| Quote: |
netstat -tanp | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | \
uniq -c |sort -nr | head -n 20 | awk '{print $1}' |
the first column will be printed.However if i try to check each $i ,something is wrong.
|
|
| Back to top |
|
 |
meitolake
Joined: 07 Oct 2007 Posts: 143 Helped: 23 Location: China
|
05 May 2008 3:03 simple script |
|
|
|
| Please show the error.
|
|
| Back to top |
|
 |