LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-14-2006, 09:22 PM   #1
Adam A Flynn
LQ Newbie
 
Registered: Jun 2004
Distribution: Gentoo
Posts: 15

Rep: Reputation: 0
Gentoo Shutdown Script


Hi,

I would like to begin running a backup script on my system to keep some of my critical files backed up. The backups involve tar`ing and bzip`ing about 300 MB worth of files, so it is somewhat resource consuming while running, meaning having it run on cron while the system is in use would become irritating when the system slows to a crawl for a few minutes when I'm in the middle of something.

So, I want this backup to run at system shutdown because I could care less if my system is slow to shut down (given that, if I'm shutting it down, that probably means I'm done using it!). Also, I would like the ability to enter 'y' or 'n' to tell the script if it is going to create a backup or just skip it.

So, two questions: How would I write a script to execute automatically on system shutdown in Gentoo, and how would I write such a script to include a prompt?

Thanks.
 
Old 05-14-2006, 09:58 PM   #2
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
Something to the effect of
----------------------------------------------------
echo -n "Do you want the backup script to run: "
read Answer

if [ "$Answer" = "y" ]; then
tar cvjf backup.tar /whatever/directory/you/want
else
echo "Backup skipped"
fi
----------------------------------------------------

Now this is not complete or syntactfully correct, I don't have a linux box at work to write/test a script to be correct but this should give you the basic outline. The READ is what allows you to get input from a prompt. Also, this will fail if you don't enter a lowercase 'y', you could build in checks to help prevent that error. Also, anything that isn't a lowercase 'y' is a No which is another bad coding, but like a said this is a quick and dirty version.

Last edited by musicman_ace; 05-14-2006 at 10:01 PM.
 
Old 05-14-2006, 11:02 PM   #3
vbisis
Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 250

Rep: Reputation: 34
You should have something like rc.0 script in /etc/rc.d or /etc/init.d ( I'm not really sure how it is named on gentoo ). This is the script executed on shutdown. You could put at the beginning of it, or whenever you like ( don't know if you have some database running which you would like to have closed uring backup. ) Just be careful taht necessary services are still running.
 
Old 05-15-2006, 02:29 AM   #4
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
oops, I left that out. In gentoo, you'll need to stick that script in the local.stop file in /etc/conf.d directory.

If you then to rc-update -s and look at local, it should be active for the default runlevel

Last edited by musicman_ace; 05-15-2006 at 02:31 AM.
 
Old 05-15-2006, 07:12 AM   #5
mneekhrey
LQ Newbie
 
Registered: Mar 2004
Location: INDIA
Posts: 6

Rep: Reputation: 0
Hi
I think thats a wonderful question as a matter of fact....Sys Admins do require these kind of scripts....



regards
Manish
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
startup and shutdown script android6011 Slackware 3 11-03-2005 04:04 PM
script at the shutdown dominant SUSE / openSUSE 4 10-15-2005 07:43 AM
shutdown script acidjuice Slackware 3 04-09-2005 05:19 PM
Shutdown script Hexane Mandriva 7 01-28-2005 01:36 AM
shutdown script Zolan Linux - Newbie 2 10-16-2004 09:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:22 AM.

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