LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   script to shutdown system - howto (https://www.linuxquestions.org/questions/linux-general-1/script-to-shutdown-system-howto-202276/)

matthewchin 07-07-2004 02:51 PM

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

Thanks,
Matthew

wolfe2554 07-07-2004 03:41 PM

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

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

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

matthewchin 07-07-2004 09:50 PM

wolfe2554,

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 ?

matthewchin 07-08-2004 03:10 AM

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 ?

matthewchin 07-08-2004 08:18 PM

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
shutdown
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.

Thanks.

matthewchin 07-11-2004 11:11 PM

[RESOLVED] by:

1) gedit /etc/root.cron as

00 2-7 * * * /etc/checkshut.sh

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

00 2-7 * * * /etc/checkshut.sh

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

content of /etc/checkshut.sh (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
else
echo >> /etc/ftpwho.txt
echo "##### System shutdown on `date` by `whoami`" >> /etc/ftpwho.txt
/sbin/shutdown -h now
fi


All times are GMT -5. The time now is 07:28 PM.