Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 07-07-2004, 03:51 PM   #1
Registered: Jun 2003
Posts: 40

Rep: Reputation: 15
script to shutdown system - howto

I run the proftpd in RH9 and allow u/l and d/l, how to write a script
such that it is cron to run after system start and yet it check

1) no traffic in proftpd (and to xferlog)
2) time is 02:30 am

Then, it issue system shutdown command for shutdown
shutdown -h now

Old 07-07-2004, 04:41 PM   #2
Registered: Apr 2003
Location: denver co
Distribution: redhat9
Posts: 156

Rep: Reputation: 30
this is pretty simple the problem is that you will need to learn scripting bash style.
you need to set 2 conditions one being time and two being transfer info then have it execute the shutdown script. the first thing I would want to do is determine if proftp is running. I do not use proftp so I have no idea. but in theory you could set proftp to shutdown after download or up load. then write something like

#script to shutdown after 2:30 am after proftp stops
ps -A|grep proftp>/var/tmp/
if [ -f /var/tmp/ && `date +%H%M ` = 230 ] ; then
rm -rf /var/tmp/
shutdown -h now
#<<<<insert what you want it to do if not>>>>>

this should do it. this makes the basic assumption though that proftp will shutdown after it is running and that the ps -A command will show it as proftp
ok bye bye now
Old 07-07-2004, 10:50 PM   #3
Registered: Jun 2003
Posts: 40

Original Poster
Rep: Reputation: 15

Thanks for reply.
The problem is I want to allow person to access my proftpd, if there is traffic (active u/l or d/l) ... it will continue after 02:30 am ....

but if 02:30 , there is no active traffic (proftfd is running), shuwdown system.

That seems difficult ?
Old 07-08-2004, 04:10 AM   #4
Registered: Jun 2003
Posts: 40

Original Poster
Rep: Reputation: 15
May be I need to describe a little details.

1) My proftpd allow people u/l or d/l data, I want to make the linux box
shutdown if it detect nobody active for proftpd at 02:30 am
(I presume they sleep) and my script test to make shutdown command

2) if people are still active at 02:30 in proftpd, the shutdown is not performed

3) this script may be scheduled to run at every 30 or 60 minutes....etc

Thanks for any more hint because I can see xferlog log down the proftpd activity but I do not know how to test when people is doing u/l or d/l ?
Old 07-08-2004, 09:18 PM   #5
Registered: Jun 2003
Posts: 40

Original Poster
Rep: Reputation: 15
I think of one solution:

to check the last line in xferlog ;
if the time difference with current time >= 2 hrs (presume no activity) then do
else do nothing

Anyone please teach me how to check the time ?

I may cron this script to run at 2:30, 3:30, 4:30, 5:30, 6:30, 7:30 etc.

Old 07-12-2004, 12:11 AM   #6
Registered: Jun 2003
Posts: 40

Original Poster
Rep: Reputation: 15

1) gedit /etc/root.cron as

00 2-7 * * * /etc/

2) crontab /etc/root.cron
3) crontab -l (to show)

00 2-7 * * * /etc/

(run hourly at 02:00-07:00 check shutdown)

content of /etc/ (update version):

#! /bin/bash
# To check if there is any active ftp user by "ftpwho"
# if nobody, issue "shutdown -h now" to shutdown system
# using a temp file "/etc/ftpwho.txt"

/usr/local/bin/ftpwho > /etc/ftpwho.txt
NOUSER="no users connected"
NOONE=`grep -i "$NOUSER" /etc/ftpwho.txt`
if [ -z "$NOONE" ] ; then
exit 0
echo >> /etc/ftpwho.txt
echo "##### System shutdown on `date` by `whoami`" >> /etc/ftpwho.txt
/sbin/shutdown -h now


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutdown the System remotely via PHP-Script? linuxuser2005 Linux - General 2 08-30-2004 12:53 PM
Graceful shutdown.. howto? rohan208 Linux - General 5 05-16-2004 03:39 PM
howto detect shutdown in progress? gw1500se Mandriva 0 04-25-2004 02:00 PM
Shutdown script wont physically turn off my system... cav Slackware 2 09-13-2003 03:06 AM
Batch Script to shutdown the system in the event of power loss scottpioso Linux - Hardware 5 03-12-2003 04:40 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration