home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3958 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  2.5 KB

  1. Path: sparky!uunet!dove!cme!libes
  2. From: libes@cme.nist.gov (Don Libes)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Simulating keyboard input in interactive programs
  5. Message-ID: <19291@muffin.cme.nist.gov>
  6. Date: 15 Sep 92 18:07:55 GMT
  7. References: <1992Sep10.163557.10186@siesoft.co.uk> <joslin.716216242@c0223.ae.ge.com> <1992Sep11.142202.11116@Princeton.EDU>
  8. Organization: National Institute of Standards and Technology
  9. Lines: 61
  10.  
  11. In article <1992Sep11.142202.11116@Princeton.EDU> subbarao@fc.hp.com (Kartik Subbarao) writes:
  12. }In article <joslin.716216242@c0223.ae.ge.com> joslin_paul@ae.ge.com writes:
  13. }>>pdel@ADS.COM (Peter Delevoryas) writes:
  14. }>>:     This is kind of related to #1. Our dial-in lines are set to
  15. }>>:     auto-log out after about 20 min. of inactivity. Short of
  16. }>>:     programming the terminal-server not to do this, how can I
  17. }>>:     keep a process going so that it always seems like I'm doing
  18. }>>:     something, even if I'm in the kitchen making a BLT (extra mayo).
  19. }>>:     Just starting up some kind of loop won't do it; it has to be
  20. }>>:     equal to a keypress from MY keyboard.
  21.  
  22. }>If you're using a pc at home, what about a TSR that puts a "space-CR"
  23. }>in the keyboard buffer every five minutes?
  24. }
  25. }This would be a good solution, but you'd also want to put some checking
  26. }that the user was *idle* for five minutes. I can imagine it now:
  27. }
  28. }% rm -rf * [hmm, do I want to do this?]
  29. }% [ OH NO, my TSR hit return for me!!! ] 
  30.  
  31. }>Second, have you tried something like
  32.  
  33. }>while :
  34. }>do
  35. }>    sleep 3600
  36. }>    echo "ls" > `tty`
  37. }>done
  38. }>
  39. }>where `tty` returns the tty device your shell is using.
  40. }
  41. }I quote again from the very article you replied to:
  42. }
  43. }>>: Just starting up some kind of loop won't do it; it has to be
  44. }>>: equal to a keypress from MY keyboard.
  45. }
  46. }Redirecting the output of echo to your tty simply writes the text 'ls' on
  47. }your terminal. Just as if you said "echo thousandlineslong" > `tty`. It
  48. }does NOT write to the input buffer of the tty. To do so, you can use the 
  49. }TIOCSTI ioctl if you have it.
  50. }
  51. }Once again, please test your solutions before you post them.
  52. }
  53. }    -Kartik
  54.  
  55. Here's a tested solution.
  56.  
  57. #!expect -f
  58. #Name: noidle
  59. #Description: expect script to run a shell which avoids being "autologged out"
  60. #        by sending a <space><delete> every hour if no other I/O has occurred.
  61. #Author: Don Libes, December 30, 1991
  62.  
  63. set timeout 3600
  64. log_user 0
  65. system stty -echo raw
  66. spawn $env(SHELL)
  67. expect    {
  68.     timeout {send " \177"; continue -expect}
  69.     -re .+ {send_user -raw $expect_out(buffer); continue -expect}
  70.     -i $user_spawn_id -re .+ {send $expect_out(buffer); continue -expect}
  71. }
  72.