Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script is meant to send commands over the network to my laptop,
- # which will then run those commands. The output will be displayed on
- # screen.
- #
- # dir1='/run/user/1000/gvfs/smb-share:server=buddha-hp-compaq-nw8440-rn039aw-ak8.local,share=buddha'
- dir1="${HOME}/buddha"
- dir2="${dir1}/run"
- bn='run_commands'
- list="${dir2}/${bn}_list.txt"
- stdout="${dir2}/${bn}_stdout.log"
- switch_f="${dir2}/${bn}_switch.txt"
- count=0
- run=0
- declare -a commands
- # trap ctrl-c and call ctrl_c()
- trap ctrl_c INT
- ctrl_c () {
- echo "** Trapped CTRL-C"
- exit
- }
- # Creates the 'switch' function, which will wait if $switch_f is
- # set to '1'.
- switch () {
- switch=$(cat "$switch_f")
- while [[ $switch -eq 1 ]]; do
- sleep 1
- switch=$(cat "$switch_f")
- done
- }
- # Creates a function called 'spin', which will show a simple animation,
- # while waiting for the command output.
- spin () {
- spinner=( ' ' '. ' '.. ' '...' )
- while [[ 1 ]]; do
- for s in "${spinner[@]}"; do
- echo -ne "\rWait${s}"
- sleep 0.5
- done
- done
- }
- if [[ ! -f $list ]]; then
- echo "Receiver list doesn't yet exist!"
- exit
- fi
- while [[ 1 ]]; do
- echo -e "\nStart typing commands, and finish with 'run'!\n"
- until [[ $run -eq 1 ]]; do
- read tmp
- if [[ $tmp != 'run' ]]; then
- commands[${count}]="$tmp"
- else
- run=1
- fi
- let count++
- done
- count=0
- run=0
- for (( i = 0; i < ${#commands[@]}; i++ )); do
- command="${commands[${i}]}"
- if [[ -z $command ]]; then
- continue
- fi
- # stdbuf -o 0 echo "$command" >&3
- echo "$command" >> "$list"
- clear
- spin &
- spin_pid="$!"
- # Waiting for the receiver script to get a chance to
- # flip the switch variable. Otherwise, output will be displayed
- # too quickly.
- sleep 0.1
- switch
- sync
- kill "$spin_pid"
- clear
- less +G "$stdout"
- unset -v command
- done
- unset -v commands
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement