Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ssh -R 2222:127.0.0.1:22 user@linuxmachine control-script
  2.  
  3. ssh -p 2222 user@localhost something.cmd
  4.  
  5. watch -n 5 ~/checker.bash
  6.  
  7. #!/bin/bash
  8. if [ -f myscript.bash ]; then
  9. sh ~/myscript.bash
  10. else
  11. echo 'checking...'
  12. fi
  13.  
  14. #!/bin/bash
  15. /cygdrive/c/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/devenv.exe
  16. rm myscript.bash
  17.  
  18. #!/usr/bin/expect
  19.  
  20. set timeout 10
  21. log_user 1
  22.  
  23. spawn bash --login
  24. expect -re {.*$} ;# Assumes a dollar sign in your prompt on local box
  25.  
  26. send "ssh remoteuser@your_remote_linux_boxr"
  27. expect "*word:*"
  28. send "REMOTE_PASSWORDr" ;# Bad security practice!! For illustration purposes only.
  29. expect -re {rn.*$} ;# Assumes a dollar sign in your prompt on your remote box
  30. puts "Connected to remote system"
  31.  
  32. set i 0
  33.  
  34. while {$i < 5} { ;# For now, we just loop 5 times. You might loop forever...
  35. send "ls ~/TasksSpoolDir | wc -lr";
  36. expect -re "rn([0-9]+)r"
  37. set taskcount $expect_out(1,string)
  38. sleep 1
  39. if { $taskcount } {
  40. # Inspect remote job files from spool directory, for example, to determine what you want to do locally
  41. send "r~32" ;# Send ~CTRL-Z to ssh
  42. expect "Stopped"
  43. send "pwd; ls; echo Do local tasks now. Remove remote job files from spool directory...r"
  44. sleep 1
  45. send "fgr" ;# Resume ssh.
  46. sleep 1
  47. send "rr"
  48. expect -re {rn.*$} ;# Assumes a dollar sign in your prompt on your remote box
  49. }
  50.  
  51. incr i
  52. sleep 1; # Sleep however long between checks for new work from spool directory
  53. }
  54.  
  55. send "exitr"
  56. expect -re {.*closed}
  57. puts "Connection to remote host closed..."
  58. send "exitr"
  59. expect "*"
  60. puts "Local bash process closed..."
  61. wait
  62.  
  63. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement