Académique Documents
Professionnel Documents
Culture Documents
#!/bin/bash
read -p "Please enter the username you wish to create : " username
username=""
fi
done
read -p "Please enter the primary group. If group not exist, it will be created : " group
else
groupadd $group
fi
done
bash="/bin/bash"
fi
homedir="/home/$username"
fi
fi
Sample Result
sudo ./linux_user.sh
Please enter the primary group. If group not exist, it will be created : test
read -p "Please enter the primary group. If group not exist, it will be created : " group
else
groupadd $group
fi
done
#check if no input
bash="/bin/bash"
fi
#check if no input
homedir="/home/$username"
fi
#if input y
fi
Shell Script to Backup Files / Directories Using rsync
May 20, 2015 | By Yevhen Duma in SHELL SCRIPTS
This article we bring shell scripts to backup your files / directories from you local linux machine to a
remote linux server using rsync command. This would be an interactive way to perform backup ,
where you need to provide remote backup server hostname / ip address and folder location. We
keep a separate file where you need to provide files / directories that need backup. We have added
two scripts where first script ask password after each file had been copied (if you have enabled ssh
authentication keys , then password will be not be asked) and in second script password will be
prompted only once.
[root@Fedora21 tmp]# ls -l
total 12
-rw-r--r--. 1 root root 0 May 15 10:43 bckrsync.sh
-rw-r--r--. 1 root root 0 May 15 10:44 bckup.txt
-rw-r--r--. 1 root root 0 May 15 10:46 dataconfig.txt
drwxr-xr-x. 2 root root 4096 May 15 10:45 docs
drwxr-xr-x. 2 root root 4096 May 15 10:44 oracledb
Script 1 :
#!/bin/bash
#next line check if entered value is not null, and if null it will reask user to enter Destination Server
while [ x$desthost = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name desthost
read -p "Destination backup Server : " desthost
#next line check if entered value is not null, and if null it will reask user to enter Destination Path
while [ x$destpath = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name destpath
read -p "Destination Folder : " destpath
Script 2 :
#!/bin/bash
#next line check if entered value is not null, and if null it will reask user to enter Destination Server
while [ x$desthost = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name desthost
read -p "Destination backup Server : " desthost
#next line check if entered value is not null, and if null it will reask user to enter Destination Path
while [ x$destpath = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name destpath
read -p "Destination Folder : " destpath
#next line check if entered value is not null, and if null it will reask user to enter password
while [ x$password = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name password.
#To hide password we are using -s key
read -sp "Password : " password
#next line finishes while loop
done