Thursday, February 02, 2023

Download Log File from Server

Write a script to login to remote Ubuntu server from a Mac OS laptop and download file from a given directory and file name

Here is a script in Bash that logs in to a remote Ubuntu server from a Mac OS laptop and downloads a file from a given directory and file name:

#!/bin/bash # Variables for the remote server login and file information user=<username> server=<server_ip_or_hostname> remote_dir=<remote_directory_path> remote_file=<remote_file_name> local_dir=<local_directory_path> # Connect to the remote server using SSH ssh $user@$server << EOF # Change to the remote directory cd $remote_dir # Download the file using SCP scp $remote_file $user@$HOSTNAME:$local_dir EOF

Replace the placeholders <username>, <server_ip_or_hostname>, <remote_directory_path>, <remote_file_name>, and <local_directory_path> with the appropriate values for your setup. Then, save the script to a file and make it executable with the chmod +x command. You can then run the script from the terminal.