LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cutting needed information (https://www.linuxquestions.org/questions/linux-newbie-8/cutting-needed-information-315074/)

Kendo1979 04-19-2005 08:55 PM

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.

bigrigdriver 04-19-2005 09:25 PM

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.

Kendo1979 04-19-2005 09:43 PM

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 ?

trevelluk 04-20-2005 08:10 AM

Yep, use the cut program:

echo `screen -ls | grep zon1` | cut -d'.' -f1

Kendo1979 04-20-2005 11:12 PM

thanks, i'll try this lates, coz i'm not on my box now :)

:D

Kendo1979 04-21-2005 04:29 PM

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.