I wanted to do a test on my linux server, I wanted each minute to show on the console hola mundo
, for this I did the following:
user@server: crontab -e
And after opening it with nano I add to the end of the file:
#prueba task para que haga 'hola mundo' cada minuto
* * * * * echo "hola mundo"
It is supposed that with that, while I am doing things in the linux bash, one should appear hola mundo
every minute, but I stay there waiting more than a minute for the message to come out but nothing comes out .
The operation of the crontab is different from what you expect. What you want is to print a message to your terminal. As far as I know, it is possible in at least two ways, the first is by printing to the interface your terminal is associated with and the second is to play carefully with the file descriptors associated with the process running on your terminal. I'll address that at the end of my answer.
First of all, outside of the command to execute, your crontab is perfect. Maybe it will help you to take a look at an answer I gave a long time ago and try to schedule another task like creating a file in a specific address, etc.
For the specific case of your question, you can use the command
tty
to see which terminal or pseudo-terminal your standard input is connected to. You can also withwho
So you can play around doing something like
And then you can put that in your crontab file. That is to say, first you obtain the associated interface (the /dev/{pts|tty}/{number}) and you send the message to it, keeping your crontab file as follows.
In my case it would be something like this:
And every minute he will fuck you with that little message on your terminal.
As @Trauma makes clear in a comment on this post, you don't always have the same interface associated with your terminal, so you'll have to use other methods if you want to write that (I hope not), I trust you were just testing the matter. I mean, it would be fun, but there are better things to have fun with.
The command
write
does that for you, it writes a message to a user. So, the crontab could look like this.The second way I can think of to write, and execute commands, in your terminal, or anyone else's, is by messing with file descriptors. You can use various programs or strategies, from the debugger , weird stuff (which always fails me) with pipes, or make a python script like this.
That when you execute it in the following way,
python ttyecho.py pts/0 "touch uno1"
execute the command in the referred terminaltouch uno1
.Only to get it to run via a scheduled task, you'd have to edit root's crontab file.
And add.
Where I remind you that pts / 0 varies in each user or each income. You could get it with a simple substitution command , but that's the subject of another question.
And that would execute an annoying command every minute in that terminal, not only print it, as in the previous example, but force the terminal to type and execute it.