Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

Rep: Reputation: 0
Gentoo Shutdown Script


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?

Old 05-14-2006, 10:58 PM   #2
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
echo "Backup skipped"

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 11:01 PM.
Old 05-15-2006, 12:02 AM   #3
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, 03:29 AM   #4
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 03:31 AM.
Old 05-15-2006, 08:12 AM   #5
LQ Newbie
Registered: Mar 2004
Location: INDIA
Posts: 6

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



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 05:04 PM
script at the shutdown dominant SUSE / openSUSE 4 10-15-2005 08:43 AM
shutdown script acidjuice Slackware 3 04-09-2005 06:19 PM
Shutdown script Hexane Mandriva 7 01-28-2005 02:36 AM
shutdown script Zolan Linux - Newbie 2 10-16-2004 10:02 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:11 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
Open Source Consulting | Domain Registration