SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old November 17th, 2004, 08:44 PM
Saiprabhu Saiprabhu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 Saiprabhu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need some help in unix scripting

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/sh

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

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

Reply With Quote
  #2  
Old November 18th, 2004, 09:54 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Use double quotres around the variables in the single bracket test.
if [ "${sleeppid}" -gt 1 ] || [ "${standpid}" -gt 1 ]

Reply With Quote
  #3  
Old November 29th, 2004, 11:44 PM
vinnie48 vinnie48 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Az
Posts: 4 vinnie48 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help

I have been trying to get this program to work but just can not get it right?Write a shell script named showparms which will disp1ay each positional parameter from the shell command line (including $0), as well as the argument count $# and the entire set of command line parameters $@. Your script should display as many positional parameters as there are arguments, but if there are more than nine arguments on the command line display only the first nine positional parameters ($1 through $9). In either case, $@ should show all of the arguments. Be sure to include appropriate comments in your script so I will know what your script is doing. Each parameter should be displayed on a separate line which shows the parameter name and has the parameter value delimited by the angle brackets < and > so that it will be possible to see an argument which consists of a null string (“”) or a blank space or spaces (“ “). As an example:



$ showparms 3 “ ” “a b c” “” “Dec 15”



Your ouput should be like this:



$# = 5

$0 = <showparms>

$1 = <3>

$2 = < >

$3 = <a b c>

$4 = <>

$5 = <Dec 15>

$@ = <3 a b c Dec 15>



The $@ is a list of all arguments. When displaying the value for $@, make sure you can account for all of the space characters which are displayed. There should not be too few or too many. In the example above, there is one space between each of the command line arguments, one additional space for the parameter $2 since it is “ ” and no additional spaces for the parameter $4 since it is “”.



Execute your script with a command line of fewer than nine arguments and a command line of more than nine arguments. When there are fewer than nine arguments you should only display as many positional parameters as there are arguments. For example, if there are four arguments you should not display the $5 argument. IF there are more than nine arguments then you should not try to display $10 since there is no such thing!
if you can help i would greatly appreciate it Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need some help in unix scripting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway