LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-23-2007, 04:21 AM   #1
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Rep: Reputation: 15
Linux scripting


Hi,
I have written a script which is as below:

`echo "cd /home/xmuser/CQ/var/bin"`
`echo ". ./xmenv.ksh"`
`echo "ftfping"` >ftfping.txt
var= echo `more ftfping.txt |grep SUCCESSFUL |wc -l`
while [ $var -ne 1 ]; do
sleep 30 |./xmstop.ksh
for PIDs in `ps -eaf |grep -E "xmuser|run.sh" | grep -E "xmocoord|/home/xmuser/|/home/db2inst1/|Coordinator|xmo" |awk '{print
$2}'`
do
kill -9 $PIDs >junk
done
done

But the error I am getting is as below:

./test: line 5: [: -ne: unary operator expected

Please advice me on the below issue.

Thanks
 
Old 03-23-2007, 07:21 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You posted the same (or similar) script here.

In that thread, I pointed out several issues and offered some suggestions---you never followed up. Some of the problems I noted there are still in the script you give here.....

Do you have:
Bash Guide for Beginners?
Advanced Bash scripting guide?

Both available at tldp.org

Last edited by pixellany; 03-23-2007 at 07:23 AM.
 
Old 03-23-2007, 08:13 AM   #3
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
Linux scripting

Ok,As per your suggestion,I did the changes(addedw hile loop etc),everything is working fine except this error.
Actually,I ahve just pasted a part of a large script.I am running short of time and I have to complete it by today.
As I am new to Linux and also do not have time left to explore,I am seeking your help.Please advice
 
Old 03-23-2007, 08:24 AM   #4
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
Change the first four lines as follows . Dont put a backtick everywhere.

cd /home/xmuser/CQ/var/bin
./xmenv.ksh
ftfping >ftfping.txt
var=`cat ftfping.txt |grep SUCCESSFUL |wc -l`

I dont know where u learned scripting but its awful.

Please follow the links given by pixellany

- zulfi
 
Old 03-23-2007, 08:35 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by 151803
Actually,I ahve just pasted a part of a large script.I am running short of time and I have to complete it by today.
As I am new to Linux and also do not have time left to explore,I am seeking your help.Please advice
starting to sound like homework....

http://tldp.org/LDP/abs/html/loops1.html

while [ $var -ne 1 ]; do

Try putting $var in quotes
Try != instead of -ne
 
Old 03-23-2007, 08:37 AM   #6
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
Linux scripting

ok...I did the changes but I got two errors this time:

./test: line 4: 0: command not found
./test: line 5: [: -ne: unary operator expected

The script name is test:


cd /home/xmuser/CQ/var/bin
. ./xmenv.ksh
ftfping >ftfping.txt
var= `more ftfping.txt |grep SUCCESSFUL |wc -l`
while [ $var -ne 1 ]; do
sleep 30 |./xmstop.ksh
for PIDs in `ps -eaf |grep -E "xmuser|run.sh" | grep -E "xmocoord|/home/xmuser/|/home/db2inst1/|Coordinator|xmo" |awk '{print
$2}'`
do
kill -9 $PIDs >junk
done
done


The second error,I can understand(var= `more ftfping.txt |grep SUCCESSFUL |wc -l` is not working but var= echo `more ftfping.txt |grep SUCCESSFUL |wc -l` is working)
The screen shot is below:

[xmuser@wgcwebsphere06 bin]$ var= `more ftfping.txt |grep SUCCESSFUL |wc -l`
-bash: 0: command not found

[xmuser@wgcwebsphere06 bin]$ var= echo `more ftfping.txt |grep SUCCESSFUL |wc -l`
0


Please advice.....
 
Old 03-23-2007, 08:43 AM   #7
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39

No space between "var=" and "`more"
var=`more ....

Not

var= `more...

Bash scripting is very sensitive to spaces and tabs.

The loop is failing because the above command fails and there is nothing in $var.
 
Old 03-23-2007, 08:45 AM   #8
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
Also do not use more .Use cat .
Even that is not needed

Just a
grep SUCCESSFUL filename | wc -l
should do.
 
Old 03-23-2007, 08:51 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Line 5:
You did not put $var in quotes as I suggested
 
Old 03-23-2007, 08:58 AM   #10
151803
LQ Newbie
 
Registered: Jan 2007
Posts: 22

Original Poster
Rep: Reputation: 15
Linux scripting

Hi zulfilee,
Ok.....Thanks a ton for ur suugestions.It worked
But the problem now I am facing is according to the script,it should execute untill the while condition is true,but the loop is being executed only once,even if I have used while loop and the condition is false.Casn you please suggest on this?

Thanks in advance
 
Old 03-23-2007, 09:04 AM   #11
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
See what the value of the variable is.

execute the script like this

sh -x ./test.sh

This will show the script flow and u can see why it doesnt work.
Maybe var is equal to one.
Also the above run will show what var`s value is and the while loop execution.
 
Old 03-23-2007, 11:21 AM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You never change the value of var inside your "while" loop. How is that loop ever supposed to finish?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
linux scripting redhatbeatswin Linux - Newbie 2 11-15-2004 02:02 PM
Linux Scripting Help droz578 Linux - Software 0 01-26-2004 08:45 AM
Linux Scripting netkepala Linux - Networking 5 02-21-2003 10:14 PM
Linux scripting... WeNdeL Linux - Newbie 7 10-20-2002 01:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration