Linux scripts
Author
Discussion

rfisher

Original Poster:

5,064 posts

313 months

Tuesday 6th April 2010
quotequote all
Anyone know how to write a text script Linux file that prints on the screen something like;

Restore image? (y) (n)

If you then press y a program is started that loads a restore image.

If you press n the system reboots after chucking the dvd out.

If you press anything else nothing happens.


Pigeon

18,535 posts

276 months

Tuesday 6th April 2010
quotequote all

#!/bin/bash

echo "Restore image? (y/n)"
read x
if [[ "$x" == [Yy] ]]; then
restoreimage
fi
if [[ "$x" == [Nn] ]]; then
umount /dev/dvd
eject /dev/dvd
shutdown -r 0
fi


1) "restoreimage" is the restore image program

2) assumes that /dev/dvd symlink is set up correctly

3) needs to be run as root for shutdown to work

rfisher

Original Poster:

5,064 posts

313 months

Tuesday 6th April 2010
quotequote all
thumbup

Excellent - thanks.