![]() |
cutting needed information
i'm trying to learn scripting in linux
the script is like this #!/bin/sh # PATH=/opt/bin/:/bin:/usr/bin:/sbin:/usr/sbin DIR=/usr/.stemp/1 DAEMON=$DIR/pl1.pl NAME=zon1 DESC="zon1" case "$1" in start) echo "Starting $DESC: $NAME" cd $DIR screen -d -m -S $NAME $DAEMON ;; check) if [[ `screen -ls |grep $NAME` ]] then echo "The $DESC is up" else echo "$DESC is not running starting it" cd $DIR screen -d -m -S $NAME $DAEMON echo -n " ... done." fi ;; *) echo "Usage: $0 {start|check}" exit 1 ;; esac exit 0 i want to modify it so that i can use cron to kill the program at certain time when i try typing screen -ls | grep zon1 on console it returns xxxxxx.zon1 where x is numbers i tried typing kill 'screen -ls | grep zon1' but it won't kill the running program if i type kill xxxx where xxx is the number i get from earlier, the program is instantly killed. is there anyway that i can gain the 'xxxx' from 'xxxx.zon1' so that i can input t to 'kill' ? any help will be apreciated. |
when you typed 'screen -ls | grep zon1', did you use the apostrophe key (') or the backtick (`), left of the number 1 key (on the US keyboard). It makes a difference. Try it again with the backtick.
|
yes i use kill `screen -ls | grep zon1`
the problem is `screen -ls | grep zon1` will result in xxxx.zon1 and kill syntax is followed by pid where xxx.zon1 is not a pid, hence failure. is there anyway to cut xxx from xxx.zon1 ? |
Yep, use the cut program:
echo `screen -ls | grep zon1` | cut -d'.' -f1 |
thanks, i'll try this lates, coz i'm not on my box now :)
:D |
thank you very much
i can use this kill `screen -ls | grep zon1 | cut -d'.' -f1` heuhuehuehuehu i never know that scripting can be this great i must study more of linux :) |
All times are GMT -5. The time now is 10:44 AM. |