Thursday, 25 February 2016 13:15

File transfer from console to console

Written by 
Rate this item
(0 votes)

Different methods for transferring files to and from linux consoles

FTP, SCP, etc

This page is always updated and may change without any notice.  It is a personal collection of links, information, tips & tricks, and guides for the given subject as I explore new ideas and projects.

 

SCP

  • -P specifies what port to use (default is 22)

Recieve remote file to local host

scp remote_user@remote_host:/path/to/remote/file /path/to/local/file

 

Copy local file to remote host

scp /path/to/local/file remote_user@remote_host:/path/to/remote/file

example: scp -P2222 ~/router_scripts/autoreboot.sh adminman@router:/tmp/mnt/data/scripts/autoreboot.sh

 

 

 

enable jffs partition on the router

Create services-start script, this will run the autoreboot.sh script in a separate process after the router starts

nano services-start

copy & paste below

#!/bin/sh
#/jffs/scripts/services-start

# start autoreboot.sh script
/bin/sh /jffs/scripts/autoreboot.sh &

 

Transfer it to the /jffs/scripts partition on your router

scp -P2222 /home/superuser/router_scripts/services-start  adminman@router:/jffs/scripts/services-start

 

Make the autoreboot.sh script

nano autoreboot.sh

copy&paste below


#!/bin/sh
#/jffs/scripts/autoreboot.sh

# Script to monitor and restart wireless access point when needed
maxPloss=10 #Maximum percent packet loss before a restart

restart_networking() {
        # Add any commands need to get network back up and running
        `/sbin/reboot`
        #logger "autoreboot: rebooting..."
}
while true; do
#give time in between runs
        sleep 120
        # First make sure we can resolve google
        if ! $(ping -q -w5 www.google.com > /dev/null 2>&1); then
                #Make a note in syslog
                logger "autoreboot: Network connection is down, restarting network ..."
                restart_networking
                exit
        fi
        # Initialize to a value that would force a restart
        # (just in case ping gives an error and ploss doesn't get set)
        ploss=101
        # now ping google for 10 seconds and count packet loss
        ploss=$(ping -q -w10 www.google.com | grep -o "[0-9]*%" | tr -d %) > /dev/null 2>&1
        if [ "$ploss" -gt "$maxPloss" ]; then
                #logger file /tmp/syslog.log
                logger "autoreboot: Packet loss ($ploss%) exceeded $maxPloss, restarting network ..."
                restart_networking
        fi
done

 

Make all of the scripts in the /jffs/scripts directory executable

chmod +x /jffs/scripts/*

 

 

You can view

 

 

 

 

 

 

 

Read 2334 times Last modified on Friday, 04 March 2016 01:37
Algis Salys

Creator and owner of algissalys.com.  Linux enthusiast, electronics tinkerer, and likes to spend time in the workshop building and creating new projects.