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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-19-2005, 08:55 PM
|
#1
|
Member
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51
Rep:
|
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.
|
|
|
04-19-2005, 09:25 PM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
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.
|
|
|
04-19-2005, 09:43 PM
|
#3
|
Member
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51
Original Poster
Rep:
|
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 ?
|
|
|
04-20-2005, 08:10 AM
|
#4
|
Member
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388
Rep:
|
Yep, use the cut program:
echo `screen -ls | grep zon1` | cut -d'.' -f1
|
|
|
04-20-2005, 11:12 PM
|
#5
|
Member
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51
Original Poster
Rep:
|
thanks, i'll try this lates, coz i'm not on my box now
|
|
|
04-21-2005, 04:29 PM
|
#6
|
Member
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51
Original Poster
Rep:
|
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 01:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|