LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2010, 09:36 AM   #1
kiranb12
LQ Newbie
 
Registered: Sep 2010
Posts: 2

Rep: Reputation: 0
How to make a cronjob or at job user interactive


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.

Regards,
Kiran

Last edited by kiranb12; 09-02-2010 at 09:39 AM.
 
Old 09-02-2010, 09:50 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Kiran this sounds remarkably like a homework question?
 
Old 09-02-2010, 10:30 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...in any case you're invited to post any (pseudo) code you've got together with any errors to receive possibly constructive comments.
 
Old 09-02-2010, 10:44 PM   #4
kiranb12
LQ Newbie
 
Registered: Sep 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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 " "


cntr=0


[ `wc -l <$DIR/users.temp` -eq 0 ] && input='Y' || input='N'


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---------------------------
 
Old 09-03-2010, 04:56 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by kiranb12 View Post
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...
 
  


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
[SOLVED] make cronjob run every 10mins qwertyjjj Linux - Newbie 2 08-13-2009 08:06 PM
User cronjob via crontab is hanging JockVSJock Programming 8 06-18-2009 09:41 PM
How to set up a cronjob as a normal user ? gauthamk Linux - Software 1 09-06-2008 10:01 AM
Can we make upgradation non-interactive? kushalkoolwal Debian 7 05-21-2007 02:56 PM
make bash interactive and change prompt DropSig Linux - Newbie 3 05-17-2004 08:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration