Gossamer Forum
Home : General : Perl Programming :

Keeping a shell process going?

Quote Reply
Keeping a shell process going?
Ok.. I've started programming in PERL again for a little project I'm working on. AOL IM bots :)

Anyways, I have an AIM bot working with a lot of features. It logs in, takes messages, replies (using Eliza), and a bunch of other stuff. However, I have to run this script through telnet.

I was wondering how I could keep this script running even without my telnet window open..

Like make it a background process. I've seen this been done with one of alex's spiders before. I believe it used fork or something. I don't know that much about UNIX, so I wanted to make sure what exactly it was that kept the perl script running (even without my telnet window open)..

If any of you guys know (i'm sure someone does), can you please give me some code examples? maybe the page number in the good ol' camel book? :)

thanks alot!

Jerry Su
widgetz sucks
Quote Reply
Re: Keeping a shell process going? In reply to
you can always write a launcher script if you don't want to write a forking daemon.

#!/bin/sh
/path/to/your.file &

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Keeping a shell process going? In reply to
Could I ask what the code in your signature does - it has been bugging me for quite a while.

Thanks.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Keeping a shell process going? In reply to
run it through a perl interp and see;)

nah, it prints out 'RTFM'

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Keeping a shell process going? In reply to
What does a forking daemon do?

Quote Reply
Re: Keeping a shell process going? In reply to
hey..

thanks! .. however as i said.. i am not familiar with unix commands and such.. this looks like a unix shell script..

how does this keep the program running even after i close my telnet?

what is the significance of '&'?

thanks!

Jerry Su
widgetz sucks
Quote Reply
Re: Keeping a shell process going? In reply to
it tells the process to run in the background. when you run the script yourself it links the process to your login process. this lets you link the process to your shell script's process that tells it to run in the background, thus letting the shell script end gracefully leaving only your actual perl script to run until it ends of its own accord.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Keeping a shell process going? In reply to
Would you login and simply run script.sh or would you run it as a cronjob?

Also is it not possible to just use perl myscript.pl & without putting the code into a .sh file?

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Keeping a shell process going? In reply to
thanks.. it works great!

paul.. you login to telnet and run it like this..

sh script.sh

you can make it a cron job if you want, it doesn't matter..

also.. the contents of my sh file contains..

#!/bin/sh
perl bot username password &

the 'username' and 'password' are just arguments.. they are there because my script logs into the AOL server..

make sure your script has an end to it though.. like it actually stops one day.. my script will stop if i send a message to it.. !shutdown

otherwise the script will never stop and you'll have to shut it down using some weird unix commands :)

Jerry Su
widgetz sucks
Quote Reply
Re: Keeping a shell process going? In reply to
Arghhhh how do I stop it...lol

I actually did it a different way....

I put

nph-import.cgi --import RDF --source="/PATH/TO/content.rdf.u8.gz" (etc) &

....into a file called import.sh and just used...

perl import.sh

......did the same job.

It has been going for 17hrs and nothing imported yet :(

The import should stop itself shouldn't it?

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Keeping a shell process going? In reply to
ps x
find the process number (the first column) of the script.

kill <process number>

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Keeping a shell process going? In reply to
Thanks again.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Keeping a shell process going? In reply to
This is part of the results from issuing ps aux - is it normal for this many?.......

httpd 17433 0.0 4.2 13976 10860 ? S 04:05 0:02 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17434 0.0 4.4 14472 11360 ? S 04:05 0:05 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17435 0.0 4.0 13636 10396 ? S 04:05 0:00 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17436 0.0 3.4 12576 9004 ? S 04:05 0:00 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17437 0.0 4.3 14084 11144 ? S 04:05 0:02 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17438 0.0 4.1 13840 10712 ? S 04:05 0:01 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17439 0.0 4.6 15012 11928 ? S 04:05 0:05 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17440 0.0 4.5 14752 11668 ? S 04:05 0:04 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17442 0.0 4.5 14800 11708 ? S 04:05 0:03 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17443 0.0 4.3 14160 11220 ? S 04:05 0:03 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17444 0.0 4.1 13988 10732 ? S 04:05 0:00 /usr/sbin/httpd -f /etc/httpd/conf
httpd 17445 0.0 4.3 14308 11212 ? S 04:05 0:02 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18314 0.0 3.4 12576 9008 ? S 04:25 0:00 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18315 0.0 4.3 14320 11216 ? S 04:25 0:01 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18316 0.0 4.5 14808 11708 ? S 04:25 0:03 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18317 0.0 4.4 14528 11404 ? S 04:25 0:03 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18318 0.0 4.2 14008 10908 ? S 04:25 0:02 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18319 0.0 4.3 14268 11180 ? S 04:25 0:02 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18320 0.0 4.2 14096 10888 ? S 04:25 0:01 /usr/sbin/httpd -f /etc/httpd/conf
httpd 18321 0.0 4.3 14208 11088 ? S 04:25 0:01 /usr/sbin/httpd -f /etc/httpd/conf



......and..........

mysql 19443 0.0 1.3 13408 3464 ? SN 04:53 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 19463 0.0 1.3 13408 3464 ? SN 04:53 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 22965 0.0 1.3 13408 3464 ? SN 06:20 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 23791 0.0 1.3 13408 3464 ? SN 06:41 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 23792 0.0 1.3 13408 3464 ? SN 06:41 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 23812 0.0 1.3 13408 3464 ? SN 06:41 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 23832 0.0 1.3 13408 3464 ? SN 06:42 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 25988 0.0 1.3 13408 3464 ? SN 07:34 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 27800 0.0 1.3 13408 3464 ? SN 08:17 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 27820 0.0 1.3 13408 3464 ? SN 08:18 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 28290 0.0 1.3 13408 3464 ? SN 08:30 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29199 0.0 1.3 13408 3464 ? SN 08:51 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29649 0.0 1.3 13408 3464 ? SN 09:02 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29669 0.0 1.3 13408 3464 ? SN 09:02 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29747 0.0 1.3 13408 3464 ? SN 09:04 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29751 0.0 1.3 13408 3464 ? SN 09:04 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 29771 0.0 1.3 13408 3464 ? SN 09:05 0:00 /usr/sbin/mysqld --basedir=/ --dat
mysql 31168 0.0 1.3 13408 3464 ? SN 09:39 0:00 /usr/sbin/mysqld --basedir=/ --dat


ps x just gives......

PID TTY STAT TIME COMMAND
31517 pts/1 S 0:00 -bash
31674 pts/1 R 0:00 ps x


Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Keeping a shell process going? In reply to
if ps x only returns that.. that means nph-import.cgi isn't running..



Jerry Su
widgetz sucks
Quote Reply
Re: Keeping a shell process going? In reply to
Hi Jerry,

Sorry, I was just giving a snippet of the results. nph-import is running as well as gzip as I am importing striaght from the gzipped rdf file.

I stopped it after 400,000 links because it had taken 4 days to get to that point and was chewing up the server.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/