Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
I need some help in this unix script

Reply  
Thread Tools
Saiprabhu's Avatar
Junior Member with 2 posts.
 
Join Date: Nov 2004
Experience: Intermediate
17-Nov-2004, 10:06 PM #1
I need some help in this unix script
Basically there are three scripts, for example walk.sh, stand.sh and sleep.sh
and the walk.sh should not run when either stand.sh or sleep.sh is running.
for this I have put in walk.sh as below:
#!/bin/ksh

sleeppid=`ps -aef | grep -i "sleep.sh" | grep -v grep | awk '{print $2}'`
standpid=`ps -aef | grep -i "stand.sh" | grep -v grep | awk '{print $2}'`
if [ ${sleeppid} -gt 1 ] || [ ${standpid} -gt 1 ]
then
echo "sleep or stand process already started"
exit
else
echo "walk process can be started"
sleep 120

when I ran the walk.sh script I got below error message,
but when sleep or stand scripts are running, and when I tried to start
walk script I got correct message as "sleep or stand process already started"
I tried hard I did't able to correct this walk.sh script,
It is saying about test argument , which I dont understand
please help as early as possible:
=======================================
ksh -x walk.sh
+ + ps -aef
+ grep -i sleep.sh
+ awk {print $2}
+ grep -v grep
sleeppid=
+ + ps -aef
+ grep -i stand.sh
+ awk {print $2}
+ grep -v grep
standpid=23104
+ [ -gt 1 ]
walk.sh[5]: test: argument expected
+ [ 23104 -gt 1 ]
+ echo sleep or stand process already started
sleep or stand process already started
+ exit
==================================
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
17-Nov-2004, 10:25 PM #2
Is that the whole walk.sh. script? I would assume you need to close the IF statement. But I do not know if scripting in KSH is different from Bash. I have never used KSH.

if
fi
Saiprabhu's Avatar
Junior Member with 2 posts.
 
Join Date: Nov 2004
Experience: Intermediate
17-Nov-2004, 10:37 PM #3
Quote:
Originally Posted by LwdSquashman
Is that the whole walk.sh. script? I would assume you need to close the IF statement. But I do not know if scripting in KSH is different from Bash. I have never used KSH.

if
fi
Thanks a for fast response,
I closed the script with fi but I missed this while pasting this script into this thread , I don't think there will be much difference between ksh and bash with regard to below logic.

#!/bin/ksh

sleeppid=`ps -aef | grep -i "sleep.sh" | grep -v grep | awk '{print $2}'`
standpid=`ps -aef | grep -i "stand.sh" | grep -v grep | awk '{print $2}'`
if [ ${sleeppid} -gt 1 ] || [ ${standpid} -gt 1 ]
then
echo "sleep or stand process already started"
exit
else
echo "walk process can be started"
sleep 120
fi
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
17-Nov-2004, 11:49 PM #4
I think I know what the problem is. If sleeppid or standpid = blank because they are not running. The comparison is not made because the value of sleeppid or standpid is not an integer.

At the beginning of your script, try setting sleeppid and standpid to 0
sleeppid=0
standpid=0
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
18-Nov-2004, 10:55 AM #5
Got up this morning and realized that my previous post will not work either, but I was on the right track. You need to test if the script is running.

Code:
if ps -ef | grep "sleep.sh" | grep -v grep >/dev/null then
echo "sleep process already started"
exit
else
echo "walk process can be started"
sleep 120
fi
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:03 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.