LinuxQuestions.org
Visit Jeremy's Blog.
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 04-19-2005, 08:55 PM   #1
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Rep: Reputation: 15
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.
 
Old 04-19-2005, 09:25 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.
 
Old 04-19-2005, 09:43 PM   #3
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Original Poster
Rep: Reputation: 15
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 ?
 
Old 04-20-2005, 08:10 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Yep, use the cut program:

echo `screen -ls | grep zon1` | cut -d'.' -f1
 
Old 04-20-2005, 11:12 PM   #5
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Original Poster
Rep: Reputation: 15
thanks, i'll try this lates, coz i'm not on my box now

 
Old 04-21-2005, 04:29 PM   #6
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Original Poster
Rep: Reputation: 15
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
 
  


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
Information needed on wireless PCI NICs Linux Compatibility maitacapac Linux - Hardware 2 06-28-2005 12:33 AM
Sed Help Needed..Cutting out peice of file farmerjoe Programming 2 02-25-2005 07:05 PM
Basic information needed! PLUGS & WIRES safe & clean- How to? yuppi21 Linux - Hardware 3 11-18-2003 12:01 PM
Information needed: Zip 250 IDE cnjohnson *BSD 1 08-28-2003 02:51 AM
rpm2tgz not cutting it Kellvyn Slackware 2 07-28-2002 03:46 AM

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

All times are GMT -5. The time now is 01:55 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
Open Source Consulting | Domain Registration