the interaction between a user and crontab - linux

How to realize that?
I need to run a crontab task. At some time, there will be a pop-out window to remind me doing something.
If I input yes in that window, that task will be done, while if no,nothing will happen
Crontab just does things in background. How to interact with it?
I could use, say
echo 'good' >/dev/pts/1
However tty1 does not exists necessarily.

Use zenity and make sure to set the DISPLAY environment variable to :0.0 when executing zenity from within the crontab as this is necessary to start GUI apps on the X server.

The usual division of labor for a problem like this is to divide the code into a server component and a client component. The server runs in the background, detached from your interactive session, and does any actual work, whilst listening for client connections. You run the client from your GUI, either interactively or as part if your GUI session, and it performs any user interactions and communicates your inputs to the server.

Related

Answer terminal prompt remotely. Pipe to a different shell session

I have a scheduled job that runs on a ec2 instances. Due to some recent third party lib change the job nows requires user interaction and can't be run automatically anymore.
The job executes a script that will prompt user input. The input is not simple y/n, and can changes so we can just echo y | myscript.sh
Compromise - I still like to continue running this job automatically on schedule, but it will ping the oncall engineer to answer prompt. Is there a way to answer the prompt remotely? If thats not possible then the engineer can ssh into the ec2 instance, but the engineer still needs a way to pipe to the shell that's awaiting for answer.

Reconnecting to a console output after system restart

For a running script on a Linux VM with a regular console output: If I disconnect from the VM the output window disappears. If I restart the VM, the script is still running but how do I get back to the output-screen?
Easy solution: use GNU screen, or an alternative like tmux to run your scripts in a persistent session. Thus, if you accidentally disconnect from your SSH session (or must shut down your computer), you can still reattach to the screen session later.
Tutorial: Using GNU Screen to Manage Persistent Terminal Sessions
Another great feature is that screen can also log the console output to a file. I use it all the time for cron jobs or other unattended tasks. I also use screen for updates (using yum, dnf or whatever), because updates can take a lot of time, and sometimes may even have to restart the network service, which would terminate your SSH session.

How to enter and leave an existing screen through script?

I'm fairly new with Linux shell scripting but have several years experience using Linux(non-hardcore).
There is an application running on my server(accessing it through SSH/putty) which is a console one. In order to ensure that it will run even even if I close my ssh client(putty), I made it run though screen.
In my script, there is a part where I want to enter this specific screen and "leave a message", then leave the screen to proceed with other things it have to perform.
How to do it exactly? Thanks!
(the console application is actually a vanilla Minecraft server)
check out 'screen' window manager http://www.gnu.org/software/screen/ with session names, see the following article:
http://www.mattcutts.com/blog/a-quick-tutorial-on-screen/

Close and reopen ssh connection without losing current process

If I open an ssh connection and start a long-running process, is there any way to close the ssh connection, and not only keep the process running, but be able to later ssh back in again, and "reattach" the process to the terminal?
I am able to do the following:
Ctrl-z
bg
disown
And that lets me keep the process running after I leave my ssh session, but I am not able to "reown" the job later; is there a way to do this? The real-world scenario is that I'd like to start a process at work, drive home, then log back in and check on it/interact with it.
I know that tmux is able to handle things like this, but I am often forgetful, or I just don't know ahead of time what process will be long-running and what won't, so I don't always remember to start the process from within tmux.
There are several ways to accomplish this. I used to use screen and that was a round about way of doing it. But check out mosh, built just for this: http://mosh.mit.edu/

Ubuntu GUI Application

I am trying to create an application that would run on ubuntu desktops,I want a scenario where when the OS boots up ,it starts my application and its required services but the main ubuntu desktop does not show so it would seem only my application is running on the device,I need help on how this can be achieved links,articles,commands etc,anything that can point me in the right direction.
It is really hard to understand what you are saying but...
You must distinguish major difference between runlevel startup and user session startup.
You did not provide any information what kind of application you have.
deamon application should be launched by upstart script
user session application should be launched by .desktop entry
If you want to launch your application instead of regular session you can hijack X session launching pipeline.
At /etc/X11/Xsession.d there are 'shell' scripts. Last one 99- calls exec. You have to provide your own (let's say 98-) script and make exec call before 99-. Scripts are launched in lexical order.

Resources