Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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."
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
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"?
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
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
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').
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.