The mysystemfiles script
This page was last updated on August 11, 2010.
Table Of Contents
- Introduction
- Requirements
- About the script
- See the script
- Get the script
- Use the script
- Obligatory Happy Ending
Introduction
This document gives a quick overview of the mysystemfiles script.
Requirements
- Kubuntu or Ubuntu 8.04 (Hardy Heron) or earlier.
- An understanding of sudo. See https://help.ubuntu.com/community/RootSudo and http://www.psychocats.net/ubuntu/graphicalsudo for detailed information.
About the script
This is a simple Bash script that backs up 12 system files to a directory on your Desktop and lets you know what it’s doing while it runs. The files it backs up are:
- ~/.bashrc
- /etc/X11/xorg.conf
- /etc/fstab
- /etc/aliases
- /etc/exports
- /etc/network/interfaces
- /etc/default/portmap
- /etc/apt/sources.list
- /boot/grub/menu.lst
- /etc/hosts.allow
- /etc/hosts.deny
- /etc/crontab
Four of the files (menu.lst, hosts.allow, hosts.deny and crontab) require root access to copy properly, so you’ll be asked for your system password.
See the script
#!/bin/bash
###########################################################################
# STEP_1 - ABOUT THIS SCRIPT #
###########################################################################
STEP_1() {
echo "#####################################################################"
echo "# mysystemfiles v0.4 #"
echo "# by Little Girl #"
echo "# http://mostlylinux.wordpress.com #"
echo "# Anyone may feel free to use and/or modify this script. #"
echo "# #"
echo "# WHAT THIS SCRIPT DOES: #"
echo "# #"
echo "# 1. This script copies 12 of your system files. #"
echo "# #"
echo "# 2. The copied files will be placed on your Desktop in a #"
echo "# directory named MySystemReports and will have the current #"
echo "# date added to their names. #"
echo "# #"
echo "# 3. Four of these files (menu.lst, hosts.allow, hosts.deny and #"
echo "# crontab) require root access to copy properly. As a result, #"
echo "# you will be asked for your system password when running this #"
echo "# script. #"
echo "#####################################################################"
echo
}
###########################################################################
# STEP_2 - HELP SECTION #
###########################################################################
STEP_2() {
echo "#####################################################################"
echo "# HOW TO USE THIS SCRIPT IN A TERMINAL: #"
echo "# #"
echo "# 1. Open a terminal window. #"
echo "# #"
echo "# 2. Change to the directory this script is in. For example: #"
echo "# #"
echo "# cd /home/Desktop #"
echo "# #"
echo "# 3. Type this command: #"
echo "# #"
echo "# bash mysystemfiles #"
echo "# #"
echo "# HOW TO USE THIS SCRIPT FROM A SHORTCUT: #"
echo "# #"
echo "# 1. Right-click this script in your file manager. Change its #"
echo "# properties so that it's executable and runs in a terminal. #"
echo "# #"
echo "# 2. Create a shortcut to the script and place the shortcut #"
echo "# anywhere you like. #"
echo "# #"
echo "# 3. Use the shortcut to run the script. #"
echo "#####################################################################"
echo
exit
}
###########################################################################
# STEP_3 - CHECK FOR DESTINATION DIRECTORY. CREATE IT IF NECESSARY. #
###########################################################################
STEP_3() {
echo "Checking if MySystemFiles directory exists on the Desktop..."
if [ -d ~/Desktop/MySystemFiles ]
then
echo "MySystemFiles directory exists. Continuing..."
echo
else
echo "Creating MySystemFiles directory..."
mkdir ~/Desktop/MySystemFiles
echo
fi
}
###########################################################################
# STEP_4 - COPY SYSTEM FILES TO DESTINATION DIRECTORY #
###########################################################################
STEP_4() {
echo "Creating a copy of the .bashrc file..."
cp ~/.bashrc ~/Desktop/MySystemFiles/.bashrc--`date +%Y-%m-%d`
echo "Creating a copy of the xorg.conf file..."
cp /etc/X11/xorg.conf ~/Desktop/MySystemFiles/xorg.conf--`date +%Y-%m-%d`
echo "Creating a copy of the fstab file..."
cp /etc/fstab ~/Desktop/MySystemFiles/fstab--`date +%Y-%m-%d`
echo "Creating a copy of the aliases file..."
cp /etc/aliases ~/Desktop/MySystemFiles/aliases--`date +%Y-%m-%d`
echo "Creating a copy of the exports file..."
cp /etc/exports ~/Desktop/MySystemFiles/exports--`date +%Y-%m-%d`
echo "Creating a copy of the interfaces file..."
cp /etc/network/interfaces ~/Desktop/MySystemFiles/interfaces--`date +%Y-%m-%d`
echo "Creating a copy of the portmap file..."
cp /etc/default/portmap ~/Desktop/MySystemFiles/portmap--`date +%Y-%m-%d`
echo "Creating a copy of the sources.list file..."
cp /etc/apt/sources.list ~/Desktop/MySystemFiles/sources.list--`date +%Y-%m-%d`
echo "Creating a copy of the GRUB menu.lst file..."
sudo cp /boot/grub/menu.lst ~/Desktop/MySystemFiles/menu.lst--`date +%Y-%m-%d`
echo "Creating a copy of the hosts.allow file..."
sudo cp /etc/hosts.allow ~/Desktop/MySystemFiles/hosts.allow--`date +%Y-%m-%d`
echo "Creating a copy of the hosts.deny file..."
sudo cp /etc/hosts.deny ~/Desktop/MySystemFiles/hosts.deny--`date +%Y-%m-%d`
echo "Creating a copy of the crontab file..."
sudo cp /etc/crontab ~/Desktop/MySystemFiles/crontab--`date +%Y-%m-%d`
}
###########################################################################
# STEP_5 - DISPLAY JOB DONE AND PROMPT USER TO CLOSE THE WINDOW #
###########################################################################
STEP_5() {
echo -n "Done! Press the Enter key to exit this script."
read keypress
}
###########################################################
# BEGIN THE SCRIPT #
###########################################################
###########################################################
# RUN THIS IF NO COMMAND LINE ARGUMENTS ARE USED #
###########################################################
if [ $# = '0' ]
then
STEP_1 | more
STEP_3
STEP_4
STEP_5
###########################################################
# RUN ONE OF THESE IF ONE COMMAND LINE ARGUMENT IS USED #
###########################################################
elif [ $# = '1' ]
then
###################################################
# Run this if a known argument is used #
###################################################
if [ "$1" = "-h" ]
then
STEP_2 | more
###################################################
# Run this if a known argument is used #
###################################################
elif [ "$1" = "--help" ]
then
STEP_2 | more
###################################################
# Run this if an unknown argument is used #
###################################################
else
echo "invalid argument"
fi
###########################################################
# RUN THIS IF MORE THAN ONE COMMAND LINE ARGUMENT IS USED #
###########################################################
else
echo "invalid number of arguments"
fi
Get the script
Download mysystemfiles_v0.4.zip
Or:
- Copy the script above.
- Paste the copied script into a text editor.
- Save it as mysystemfiles somewhere on your computer.
Use the script
- Open a terminal window.
- Change to the directory the script is in. For example, if the script is on the Desktop, you would type this command:
- Press the Enter key.
- Run the script by typing this command:
- Press the Enter key.
- Type in your password when asked.
- When the script finishes running, press the Enter key and close the terminal window.
- Copies of the files will be in the MySystemFiles directory on your Desktop. You can move the directory to another location on your computer or keep it on your Desktop. Advanced users can modify the script so that it saves the files to a different location.
cd ~/Desktop
bash mysystemfiles
Obligatory Happy Ending
And they all lived happily ever after. The end.
![]() |
The mysystemfiles script from http://mostlylinux.wordpress.com is Copyright © 2007 – 2011 by Little Girl, licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License, and offered free of charge without warranty of any kind, either expressed or implied. |

