LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-04-2008, 01:03 PM   #1
vijay_aras
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Rep: Reputation: 0
Linux rescue mode reading input question


Hi I wrote a resue script that will read input from user in rescue mode, the problem is

if I use "read ANY" to read it will not be compatiable for backspace, simply backspace does not work. But after I replace "read ANY" with "read -e ANY" backspace seems to be working but the cursor becomes in the first line of the sentence, meaning overwriting the prompt statement. how do i read a choice from user when I display a menu, that will not affect back space issue and the cursor issue that I have.

regards,
Vijay
 
Old 01-05-2008, 07:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Maybe it's in the termcap settings of the rescue mode env or else the script? Posting your script may help.
 
Old 01-07-2008, 10:57 AM   #3
vijay_aras
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Original Poster
Rep: Reputation: 0
here is the script

#!/bin/bash

trap '' 0 1 2 3 15 20
shopt -s extglob

#just in case disable control characters in rescue menu
/bin/stty -ixon
/bin/stty eof ''
/bin/stty intr ''
/bin/stty susp ''
/bin/stty rprnt ''
/bin/stty kill ''
/bin/stty quit ''
/bin/stty werase ''

IMG_DIR="/root"
RESCUE_SCRIPTS_DIR="/BMrescueScripts"

export IMG_DIR
export RESCUE_SCRIPTS_DIR

function fn_press_any_key_to_return_to_menu()
{
echo
echo " << Press Enter to return to previous menu. >>"
read -e ANY
}

while [ "1" = "1" ]
do
clear
echo Rescue AC Start-up Menu. Use with extreme caution.
echo
echo $'\t1) Force System Recovery'
echo $'\t2) Create System Backup Image'
echo $'\t3) Display Backup Images'
echo $'\t4) FTP Menu'
echo $'\t5) Network Interface Menu'
echo $'\t6) Manually run File System Check Utility (fsck)'
echo
echo
echo $'\t9) Reboot'
echo
echo WARNING! - Forcing system recovery will erase all files, and reinstall
echo the image installed at the factory.
echo
echo Reboot will restart the system back into Normal mode.
echo
echo If you have any questions about these options, please contact Support.
echo
echo "Your choice: "
read -e OPT
if [ "$OPT" = "1" ]; then
clear
#re-initialize variables
IMAGE=""

echo
cd $IMG_DIR

DEF_IMAGE=$(ls | grep "main_part.tgz")
if [ -z "$DEF_IMAGE" ]; then
DEF_IMAGE=$(ls | grep "-rescue.tgz")
fi
USER_IMAGE=$(ls | grep "-rescue-user.tgz")

if [ -z "$DEF_IMAGE" ] && [ -z "$USER_IMAGE" ]; then
echo "Error: No Images to restore!"
echo "Press Enter to return to the main menu"
read -e ANY
continue
fi

if [ -z "$USER_IMAGE" ] && [ ! -z "$DEF_IMAGE" ] ; then
echo "Only Default Image is available!"
IMAGE="$DEF_IMAGE"
fi
if [ -z "$IMAGE" ] && [ -z "$DEF_IMAGE" ] && [ ! -z "$USER_IMAGE" ]; then
echo "Only User Image is availabe!"
IMAGE="$USER_IMAGE"
fi

while [ -z "$IMAGE" ];
do
clear
echo "Backup Image List"
echo "-----------------"
echo " 1) Default image: $DEF_IMAGE"
echo " 2) User image: $USER_IMAGE"
echo
echo -n "Please select which image to use for restoring: "
read -e SEL
case $SEL in
1)
IMAGE="$DEF_IMAGE"
;;
2)
IMAGE="$USER_IMAGE"
;;
*)
continue
;;
esac
done
echo "Selected Restore Image is: $IMAGE"
cd -

echo -n "This procedure is irreversible, do you wish to continue (Y/N)? "
read -e CONF
if [ "$CONF" = "Y" ]; then
echo
echo "Performing System recovery, this may take a while..."
echo
echo "Remove /original_root"
rm -fr /original_root

echo -n "Cleaning out normal partitions..."
# Remove everything from current partitions by mounting them one my one onto
# temporary mount point and removing everything from them
mkdir -p /root/tmp_mp
# /dev/hda1
mount /dev/hda1 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp
# /dev/hda5
mount /dev/hda5 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp
# /dev/hda3
mount /dev/hda3 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp
# /dev/hda6
mount /dev/hda6 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp
# /dev/hda7
mount /dev/hda7 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp
# /dev/hda8
mount /dev/hda8 /root/tmp_mp
rm -fr /root/tmp_mp/*
umount /root/tmp_mp

rm -fr /root/tmp_mp
echo "done."

#Mount partitions
echo "Mounting Normal Mode Partitions"
echo -n "mounting root..."
mkdir /original_root
mount /dev/hda1 /original_root
#determine if backup image uses or controller fs
FS_TYPE=$(tar --to-stdout -zxf $IMG_DIR/$IMAGE etc/fstab | grep "controller")
if [ -n "$FS_TYPE" ]; then
FS_TYPE="controller"
else
FS_TYPE="controller2"
fi
echo "done."

$RESCUE_SCRIPTS_DIR/mount_main_partitions.sh $FS_TYPE

echo -n "Restoring main partition..."
cd /original_root
tar -zxf $IMG_DIR/$IMAGE
cd -
echo "done!"

echo -n "Verifying volume labels..."
# check if the original image uses volume labels to mount partitions
# if yes, put the proper volume labels
# if no, remove volume labels
USING_LABEL=$(grep "chantr" /original_root/etc/fstab)
if [ -n "$USING_LABEL" ]; then
e2label /dev/hda3 "/var/log/"
e2label /dev/hda6 "/var/log/"
e2label /dev/hda7 "/var/log/"
e2label /dev/hda8 "/var/log/"
else
e2label /dev/hda3 ""
e2label /dev/hda6 ""
e2label /dev/hda7 ""
e2label /dev/hda8 ""
fi
echo "done!"

echo "Unmount all partitions to save restoration"
umount /dev/hda8
umount /dev/hda7
umount /dev/hda6
umount /dev/hda3
umount /dev/hda5
umount /dev/hda1

echo "System Recovery Complete!"
echo "Reboot the system for changes to take effect."
fn_press_any_key_to_return_to_menu
else
echo "Aborting..."
fi
sleep 3
elif [ "$OPT" = "2" ]; then
echo "Warning: All logs from the main partition will be lost due to creating a backup image."
echo "Warning: Any previous user backup image will be deleted first."
echo
echo "Proceed with image backup (Y/N): "
read -e CONF
if [ "$CONF" = "Y" ]; then
echo
PREV_IMG=$(ls $IMG_DIR | grep "-rescue-user.tgz")
if [ -n "$PREV_IMG" ]; then
echo "Removing previous user-created backup."
rm -f $IMG_DIR/$PREV_IMG
fi
clear
echo
echo "Performing system backup. Please be patient and do not reboot the box"
$RESCUE_SCRIPTS_DIR/create_main_part_backup.sh user
fn_press_any_key_to_return_to_menu
fi
elif [ "$OPT" = "3" ]; then
clear
cd $IMG_DIR
echo "Currently stored backup images: "
echo "--------------------------------"
D_IMG=$(ls | grep "main_part.tgz")
if [ -z "$D_IMG" ]; then
D_IMG=$(ls | grep "-rescue.tgz")
fi
U_IMG=$(ls | grep "-rescue-user.tgz")
echo -n " 1) Default Image: "
if [ -n "$D_IMG" ]; then
echo "$D_IMG"
else
echo "Not Available"
fi
echo -n " 2) User Image: "
if [ -n "$U_IMG" ]; then
echo "$U_IMG"
else
echo "Not Available"
fi
cd -
echo
fn_press_any_key_to_return_to_menu
elif [ "$OPT" = "4" ]; then
$RESCUE_SCRIPTS_DIR/menu.sh
elif [ "$OPT" = "5" ]; then
$RESCUE_SCRIPTS_DIR/interface.sh
elif [ "$OPT" = "6" ]; then
FSCK_OPT=1
while [ "$FSCK_OPT" != "7" ]
do
clear
echo
echo $'\tFile System Check Menu'
echo $'\t----------------------'
echo $'\tPlease choose on which Normal Mode Partition'
echo $'\tyou would like to perform manual file system check:'
echo $'\t\t1) main root'
echo $'\t\t2) home'
echo $'\t\t3) cdr'
echo $'\t\t4) logs'
echo $'\t\t5) reports'
echo $'\t\t6) trace'
echo
echo $'\t\t7) Return to Main Menu'
echo
echo "Your choice: "
read -e FSCK_OPT

case $FSCK_OPT in
1) /sbin/fsck /dev/hda1
fn_press_any_key_to_return_to_menu
;;
2) /sbin/fsck /dev/hda5
fn_press_any_key_to_return_to_menu
;;
3) /sbin/fsck /dev/hda3
fn_press_any_key_to_return_to_menu
;;
4) /sbin/fsck /dev/hda6
fn_press_any_key_to_return_to_menu
;;
5) /sbin/fsck /dev/hda7
fn_press_any_key_to_return_to_menu
;;
6) /sbin/fsck /dev/hda8
fn_press_any_key_to_return_to_menu
;;
7) echo
echo " << Press Enter to return to MAIN menu. >>"
read -e ANY
;;
*) ;;
esac
done
elif [ "$OPT" = "99" ]; then
clear
unset IMG_DIR
unset RESCUE_SCRIPTS_DIR
exit
elif [ "$OPT" = "9" ]; then
echo "Rebooting in 2 seconds..."
unset IMG_DIR
unset RESCUE_SCRIPTS_DIR
sleep 2
reboot
else
echo "Wrong user input"
sleep 1
fi
done
 
Old 01-09-2008, 06:37 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
If I use "hello() { echo -n "Enter"; read -e -p ', give, you should here: ' ANY; echo "${ANY:=enter?}"|od -a|xargs; }" this works, I don't see any "erase" (backspace) problems. Also your script doesn't show possibly related stuff. I'm sure it's rescue mode terminal initialisation or readline itself not initialising properly. What does 'env' output look like in rescue mode? Or don't you mean 'runlevel 1' by "rescue mode"?
 
Old 02-05-2008, 03:59 PM   #5
vijay_aras
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Original Poster
Rep: Reputation: 0
have a look at the script - need help on read -e ANY

if I use "read ANY" to read it will not be compatiable for backspace, simply backspace does not work. But after I replace "read ANY" with "read -e ANY" backspace seems to be working but the cursor becomes in the first line of the sentence, meaning overwriting the prompt statement. how do i read a choice from user when I display a menu, that will not affect back space issue and the cursor issue that I have.











#!/bin/sh

# -------------------------------
# / ftp_get_image.sh /
# ------------------------------
# helper script used by ftp_menu to download a file
# from the ftp server
# Input parameters:
# 1) ftp ip
# 2) ftp port
# 3) user name
# 4) password
# 5) directory on the ftp server where the file to be downloaded is
# 6) filename
#

if [ "6" -ne "$#" ]; then
echo "Incorrect number of arguments. FTP settings not configured properly!"
echo "Press Enter to return to ftp menu."
read -e ANY
exit
fi

ftp -n $1 $2 <<END_SCRIPT
user $3 $4
bin
cd $5
get $6
quit
END_SCRIPT
 
Old 02-06-2008, 12:42 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
You post this nearly a month after my last reply and you don't reply to anything I wrote, so that means you're not helping me help you. Sorry.
 
Old 02-07-2008, 10:36 AM   #7
vijay_aras
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Original Poster
Rep: Reputation: 0
I was on vacation thats why

i got a baby, so i was on vacation for a while.

This is you posted. I haven't quite get what you are saying.
If I use "hello() { echo -n "Enter"; read -e -p ', give, you should here: ' ANY; echo "${ANY:=enter?}"|od -a|xargs; }" this works, I don't see any "erase" (backspace) problems. Also your script doesn't show possibly related stuff. I'm sure it's rescue mode terminal initialisation or readline itself not initialising properly. What does 'env' output look like in rescue mode? Or don't you mean 'runlevel 1' by "rescue mode"?


if you look at this one below, look what i have in "read -e ANY" it was originally "read ANY" thats all I changed, back space is working fine, but the user prompt message is being overwritten by the cursor now.



if [ "6" -ne "$#" ]; then
echo "Incorrect number of arguments. FTP settings not configured properly!"
echo "Press Enter to return to ftp menu."
read -e ANY
exit
fi
 
Old 02-07-2008, 12:07 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Quote:
Originally Posted by vijay_aras View Post
i got a baby, so i was on vacation for a while.
Congratulations. I hope all is well.


Quote:
Originally Posted by vijay_aras View Post
I haven't quite get what you are saying.
Consider where you use (ex line numbers):
Code:
 65 echo
 66 echo "Your choice: "
 67 read -e OPT
If you change it to:
Code:
 65 echo
 66 echo -n "Your choice: "
 67 read -e -p '[y|n]' OPT
Does that work for you?


Quote:
Originally Posted by vijay_aras View Post
if you look at this one below, look what i have in "read -e ANY" it was originally "read ANY" thats all I changed, back space is working fine, but the user prompt message is being overwritten by the cursor now.
See, that's what I mean. In my BaSH shell version 3 and TERM set to "xterm-color" this doesn't give any errors. That's why I think that it may have anything to do with your terminal initialisation. That's why I asked you to check your environment settings ('env').
 
Old 02-12-2008, 11:00 AM   #9
vijay_aras
LQ Newbie
 
Registered: Jan 2008
Posts: 6

Original Poster
Rep: Reputation: 0
question about normal mode and rescue mode

No it doesn't work

read -e -p '[y|n]' OPT

what this -p option means

when I try, with

read OPT
read -e OPT
read -p '[y|N] option in my linux work station works the same,

the script that i am running in a linux box, which is almost as a router, and when in rescue mode, this script doesn't behave the same as i use -e or -p option.

what so special about rescue mode, is there any difference in rescue mode and normal mode shell scripts.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rescue mode question kscott121 DamnSmallLinux 0 09-08-2005 05:42 PM
mounting '/ ' file system on linux rescue mode ?? bipinkdas Red Hat 2 01-25-2005 10:16 AM
Rescue mode. How do I start up Linux? Epud Linux - Laptop and Netbook 1 04-19-2004 01:17 PM
Why is it so difficult to reinstall RH9's Boot loader using the Linux Rescue mode? Seph64 Linux - Distributions 10 10-04-2003 08:24 PM
RedHat 9.0 /sbin/loader hangs in linux rescue mode subrakrishnan Linux - Newbie 2 07-28-2003 08:00 AM


All times are GMT -5. The time now is 04:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration