LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-07-2004, 02:51 PM   #1
matthewchin
Member
 
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

Thanks,
Matthew
 
Old 07-07-2004, 03:41 PM   #2
wolfe2554
Member
 
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

#/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
 
Old 07-07-2004, 09:50 PM   #3
matthewchin
Member
 
Registered: Jun 2003
Posts: 40

Original Poster
Rep: Reputation: 15
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 ?
 
Old 07-08-2004, 03:10 AM   #4
matthewchin
Member
 
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, 08:18 PM   #5
matthewchin
Member
 
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
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.
 
Old 07-11-2004, 11:11 PM   #6
matthewchin
Member
 
Registered: Jun 2003
Posts: 40

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


Reply



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 11:53 AM
Graceful shutdown.. howto? rohan208 Linux - General 5 05-16-2004 02:39 PM
howto detect shutdown in progress? gw1500se Mandriva 0 04-25-2004 01:00 PM
Shutdown script wont physically turn off my system... cav Slackware 2 09-13-2003 02:06 AM
Batch Script to shutdown the system in the event of power loss scottpioso Linux - Hardware 5 03-12-2003 03:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:37 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