3

I have the need for teachers to fill in electronic registers in remote areas, and they need to be able to do it fast and with the least fuss necessary. To accomplish this I have set up netbooks with a "vanilla" Debian 6 install with nothing on it other than rdesktop. The netbook logs in automatically (via /etc/inittab) and then I use the .profile the .bashrc files in the user's home directory to relaunch networking (to fix a dhcp bug), launch startx for window server, and then launch rdesktop into a terminal server to take the register. This works flawlsessly, and the teacher is presented with their register in less than 30 seconds.

What I would like to happen is that when they close rdesktop (log out of the terminal server) the laptop shuts down, but have so far failed. I had originally tried just adding the shutdown command to the next line of the script, but for some unexplainable reason the script appears to run out of order and the machine is shutting down before rdesktop runs. I think this is because rdesktop is "forking'. Is there a way I can wait for rdesktop to quit before the rest of the script runs?

I have already tried: sleep before the shutdown wait before the shutdown

I know how I could do this in visual basic / vbscript / batch file but I am very new to linux and am starting to think I am missing the obvious or being stupid!

My files are as follows:

/home/user/.profile:
sudo dhclient
startx -- :1

/home/user/.bashrc:
rdesktop -u "" -k en-gb -f servername

(The lack of username is intentional as it causes the terminal server to not pre-fill the username for login with the linux username of the netbook)

MikeyB
  • 38,725
  • 10
  • 102
  • 186

2 Answers2

3

What may actually be happening is that .bashrc is being run more than you think.

If it's run and there's no X screen or DISPLAY variable, rdesktop will fail and then the shutdown will run. @dimmer's fix should handle that, though there's a cleaner way.

It should work if you put the shutdown command after the startx command and put the rdesktop command in the user's .xinitrc. This may be a little cleaner and more robust. Try it out.

MikeyB
  • 38,725
  • 10
  • 102
  • 186
  • From a quick google about that file, this suggestion is looking promising. I will try both suggestions tomorrow and see how we get on. It seems it is potentially very obvious when you know how! – James Howell May 12 '11 at 21:02
  • Just tried this in a virtual machine I threw together to replicate my setup at work, and it appears that it does what I need it to. I will try it tomorrow to make sure, but this looks like the answer I was looking for. – James Howell May 12 '11 at 21:42
0

Have you tried this:

/home/user/.bashrc

rdesktop -u "" -k en-gb -f servername && sudo shutdown -h now
chrishiestand
  • 974
  • 12
  • 23
  • I will try this when I am back in front of the machine tomorrow. What does the && part of the command actually do? – James Howell May 12 '11 at 20:15
  • It means 'only execute the next command if the previous command exited successfully'. `||` is the opposite. – MikeyB May 12 '11 at 20:28
  • 1
    If his rdesktop is forking and the parent is exiting then this will cause the shutdown to happen immediately. – Mark Wagner May 12 '11 at 20:42