Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Quick overview, I have created a script that reboots the laptop after x amount of time and x amount of cycles. I have added the script to the start-up applications and the script does seem to be running in the background but never opens a terminal Window. Am I missing something?

Adding Code (this is saved in a file called countdown.sh)

#!/bin/bash

# check if passed.txt exists if it does, send to soak test

if [ -f passed.txt ];
then
echo reboot has passed $nol cycles
sleep 5;
echo Starting soak tests 
sleep 5;
rm testlog.txt;
rm passed.txt;
phoronix-test-suite run quick-test
exit 0;
fi

# check if file testlog.txt exists if not create it

if [ ! -f testlog.txt ];
then
echo >> testlog.txt;
fi

# read reboot file to see how many loops have been completed

exec < testlog.txt
nol=0
while read line
do
nol=`expr $nol + 1`
done

# start the countdown, x is time limit

let x=10; 
while [ $x -gt 0 ]; 
do clear; 
figlet "Rebooting in..."; 
figlet $x; 
let x-=1; 
sleep 1;
done;
echo reboot success $nol >> testlog.txt;
shutdown -r now;

# set how many times the script should shutdown the laptop

reboot_count=1

# if number of reboots matches nol's then stop the script
# create a new text file called passed.txt

if [ "$nol" == "$reboot_count" ];
then
echo reboot passed $nol cycles >> passed.txt;
fi
share|improve this question
    
Get the number of lines with nol=$(wc -l testlog.txt) –  artistoex Sep 11 '12 at 9:18

1 Answer 1

up vote 1 down vote accepted

shell scripts don't automatically open windows on your desktop. You have to include code to do that if that is what you want.


Update 1

One way to do this is to use Xdialog.

Note you may need to install it using sudo yum install Xdialog or apt-get install Xdialog (or whatever command is appropriate for your Unix/Linux distribution's package manager).

There are examples in /usr/share/doc/xdialog*/samples, here's one

Using this tool you can have the background script display messages on the system console (assuming it is running an X server). You may have to set the value of the DISPLAY environment variable so the program knows on which screen it should display the dialog. This also works for remote PCs etc if they run an X server (e.g. Xming on Windows).

Heres a quick example

Xdialog test


Update 2

Note: the above is not the usual way a system background task communicates with users. Normally I'd just have the task write it's messages to a log file (and maybe use logger to write to syslog), then anyone who is interested can just use tail -f logfilename to see current status of the background process.

If you need to bring to someone's attention the completion of a task you might instead send them an e-mail or trigger an SNMP alert.

share|improve this answer
    
Hi RedGritty would I write such code in the actual shell script? I'm guessing this would work as the script is actually being run just not showing a window? Or would it need to go into an external file that runs on start-up? –  twigg Sep 11 '12 at 9:23
    
@twigg: I'll update answer –  RedGrittyBrick Sep 11 '12 at 9:24
    
@twigg start an X-Server –  artistoex Sep 11 '12 at 9:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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