1

I have little experience with linux and hardly ever wrote an shell script, but needed a workstation with both windows and linux to do certain calculations. The workstation is however mostly used remotely from a windows computer.

I installed windows on one partition and linux on the other (using grub2 for dual booting). I wrote an small shell script which reboots the computer into windows from linux unsing grub-reboot basically following https://wiki.debian.org/GrubReboot

#!/bin/bash
gksudo grub-reboot "Windows 7 (loader) (on /dev/sda1)"

This works perfectly and when rebooting windows starts and when rebooting again ubuntu starts.

For working trough remote connection I installed teamviewer, both on windows and ubuntu (teamviewer 9, directly from the teamviewer website).

Now my problem is as following. When I start my computer I can use teamviewer without problem in Ubuntu. When I reboot to windows using the above script I can also use teamviewer. Next when I reboot from windows to Ubuntu I cannot connect to teamviewer. If I reboot again (which I cannot do when I am at a remote location) teamviewer works perfectly again in Ubuntu.

I tried looking if (when I cannot use teamviewer) the the teamviewer service is running in Ubuntu. Which seems to be the case, because when I try the code below it tells me the service is running. If I stop and start the service again teamviewer still doesn't work.

sudo teamviewer --daemon enable (or start)

My final (not perfect) solution to the problem would be to make a script which basicly reboots ubuntu once when it starts. I wrote a small shell script for it which I placed in the etc/init.d folder. The script basicly makes an .txt file and checkes if this is present. If the computer reboots teamviewer will work again. But this script gives problems.

#!/bin/bash
if [ ! -f /tmp/reboot.txt ];
then 
    echo "test" > /tmp/reboot.txt 
    sleep 3s
    reboot
else
fi
exit 0

This script makes the reboot.txt but doesn't reboot. I also tried removing the else but when I did that it keeps rebooting continuously.

Can someone either help me with my teamviewer problem, on how to easily solve the problem that it doesn't work. Or help me with my shell script on how to restart Ubuntu one time when it boots. This last solution definitely makes it possible for me to use teamviewer without problems and the extra 30 seconds wait for the extra reboot are no problem so I think that would be the most easy solution.

UPDATE: I tried what MilliByte answered below without success.

0

I'd change the script to read:

#!/bin/bash
if [ ! -f /tmp/reboot.txt ]
then 
    echo "test" > /tmp/reboot.txt 
    sync
    reboot
fi
exit 0

The sync will flush changes to the file system before the reboot.

  • Hi millibyte. I understand the difference between sync and sleep (after googleling) which sounds more logical and removing the else. However when I previously used my function without the else (so your script only sleep 3s instead of sync) the computer kept rebooting. Will your script also have this problem? As the previous script without the else did make the reboot.txt file correctly before rebooting. – JH6 Dec 2 '14 at 13:15
  • I tried this solution but it doesn't work. Gives the same problem. The system keeps rebooting. Any further ideas? – JH6 Dec 6 '14 at 17:10

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.