![]() ![]() This check should not replace testing the archive file. This is useful for a quick file size check of the archive file. Ls -lh $dest: optional statement prints a -l long listing in -h human readable format of the destination directory. Otherwise the tar output will be sent to STDOUT. Z: filter the archive through the gzip utility compressing the archive.į: output to an archive file. ![]() Tar czf $dest/$archive_file $backup_files: the tar command used to create the archive file. ![]() Status messages: optional messages printed to the console using the echo utility. The directory needs to be created and in this case mounted before executing the backup script. $archive_file: the full archive filename. Using the hostname in the archive filename gives you the option of placing daily archive files from multiple systems in the same directory. $hostname: variable containing the short hostname of the system. There are other ways to accomplish this including using the date utility. This is used to create an archive file for each day of the week, giving a backup history of seven days. $day: a variable holding the day of the week (Monday, Tuesday, Wednesday, etc). The list should be customized to fit your needs. $backup_files: a variable listing which directories you would like to backup. # Long listing of files in $dest to check file sizes. Tar czf $dest/$archive_file $backup_files #!/bin/bashīackup_files="/home /var/spool/mail /etc /root /boot /opt"Įcho "Backing up $backup_files to $dest/$archive_file" The archive filename is determined using additional command line utilities. The following shell script uses tar to create an archive file on a remotely mounted NFS file system. tar can also filter the files through compression utilities, thus reducing the size of the archive file. The tar utility creates one archive file out of many files or directories. The archive can also be created on a remote file system such as an NFS mount. The archive file can then be moved or copied to another location. For example, a script can be used to configure which directories to backup, and pass those directories as arguments to the tar utility, which creates an archive file. One of the simplest ways to backup a system is using a shell script. In this article, we have looked at two different ways to automate SSH login, and also created shell script for it.Multi-node Configuration with Docker-Compose Run the shell script with the following command. In both the above cases, you need to make your shell script executable. Open terminal and run the following command to create a blank shell script. $ sudo ssh can also place the above command in a shell script if you want. ssh/authorized_keysįrom now on, you can easily log in with the following command. ssh/authorized_keys to make sure your keys have been copied correctly. Log into your SSH server with the following command. Replace user and host below with your remote SSH username & host IP address respectively. It will automatically log into your SSH server and copy keys from your local machine to remote SSH server. Your public key has been saved in /home/username/.ssh/id_rsa.pub.Ĭopy your keys in your remote SSH server using the following ssh-copy-id command. Your identification has been saved in /home/username/.ssh/id_rsa. $ ssh-keygen -t rsa -b 2048Įnter file in which to save the key (/home/username/.ssh/id_rsa):Įnter passphrase (empty for no passphrase): At the end, it will create the keys files and give you their paths. Open terminal and run the first command shown below. If you don’t use password, then you need to generate public RSA keys to automate SSH login. You can use locate command to find their paths. sudo usr/bin/sshpass -p your_password /usr/bin/ssh paths may be different based on your system. If the above shell script does not work for you, replace sshpass and ssh commands above with their full paths. Sudo sshpass -p your_password ssh and close the file. $ sudo vi auto_ssh_login.shĪdd the following shell script with the above command. Open terminal and run the following command to create an empty shell script file. $ sudo sshpass -p your_password ssh can also add the above command in a shell script. Replace password, user and host with your SSH password, SSH username and SSH host IP address. Run the following command to log into SSH using your password. Open terminal and run the following command to install sshpass $ sudo apt-get install sshpass If you log into SSH using password and not SSH keys then there are many third-party tools to help you automate SSH login. Here are the different ways to automate SSH login. In this article, we will look at how to create shell script to automate SSH login – with SSH keys or with password. Sometimes you may need to automate SSH login on your system. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |