ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Any pointers to make a shell script in cronjob or using at to be user interactive. We have a requirement to script a program where it prompts the users in CUI for feedback and capture the output in a text file and act based on the feedback.
For eg: At pre-defined time i should prompt the acitve users whether it is ok to shutdown, whose feedback would be captured in a text file. Post which act on the updates in the text file.
Below is the shell script we are using, which works fine when executed at shell prompt, but fails to come to foreground when scheduled in cron. I know that the cron cannot be attached to tty device, but is there any alternate solution..??? also should be compatible for CUI only, and NOT GUI.
#!/usr/bin/ksh
DIR=/var/power_shutdown/scenario1
export DIR
echo "***************************************************"
echo "# ------URGENT------ #"
echo "#### AUTO POWER SHUTDOWN STARTED #####"
echo "# ------------------ #"
echo "****************************************************"
echo " "
while [ $cntr -eq 0 ]
do
echo "DO YOU WANT TO SHUTDOWN[Y|N]"
read -t10 input
if [ $input != 'Y' -a $input != 'y' -a $input != 'n' -a $input != 'N' ]
then
echo "INVALID INPUT !! ENTER INPUT AGAIN"
# Read the input again
cntr=0
else
if [ $input == 'Y' -o $input == 'y' ]
then
USER=`who am i | awk '{print $1}'`
echo "$USER::Y">>$DIR/fd.txt
cntr=1
else
USER=`who am i | awk '{print $1}'`
echo "$USER::N">>$DIR/fd.txt
echo "-----------------------------"
echo "DEFAULTLY SNOOZED FOR 1 HOUR"
echo "-----------------------------"
cntr=1
fi
fi
done
-------------------------end of the script---------------------------
Below is the shell script we are using, which works fine when executed at shell prompt, but fails to come to foreground when scheduled in cron. I know that the cron cannot be attached to tty device, but is there any alternate solution..??? also should be compatible for CUI only, and NOT GUI.
If you would be dealing with the GUI the process would be to find out find out which target user is logged into which $DISPLAY, export the DISPLAY for the process that will be using it, get yourself Xauth'ed for the target users Xsession and fire off a Zenity, Gdialog or equivalent script. For the CLI the same won't work unless you force everybody to use say GNU/Screen (or tmux?) and manage to mess up "-X" to do Something Completely Different. The CLI (Command Line Interface) and GUI (Graphical User Interface) TLA I know but CUI (Composite User Interface?) I don't know about...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.