1

I initially started this script for something else, thinking it would be nice for the script to handle the full process automatically, reboot, and start more script stuff. Then I realized I had a problem, as another process I need to run does actually require user input. While I have since solved that secondary problem so it doesn't require user input anymore, I'd still like to know how to do this. I'm fairly new to Linux, been working with it rather intensely with scripting a process over the last month and a half. However, there's still a lot of things I don't know.

So with all that being said, I want to run a script automatically through some method. I've been using crontab and a bash script, but it doesn't necessarily need to be crontab. I usually use this to put the script into crontab from another script, and then write the main script to output a script like the one below the crontab job being inserted.

(crontab -l 2>>/dev/null; echo "* * * * * /home/pi/Public/test2") | crontab

I could care less on how it's done to get the script to appear in a terminal to be interacted with, as long as I have the ability to schedule when that happens. Like on a restart.

#!/bin/bash
echo 'This is a test.'
echo 'This is a written test.' >> /home/pi/Public/testwrite.txt
sleep 10

And yeah, I realize this one goes every minute but it's just for testing purposes to make sure it's working. The scripts I'm using all use "#!/bin/bash" at the top and are given execution rights. It works when started manually and when called in crontab, though the window never appears and instead works in the background. I would like a way to be able to force it into the foreground to either be read or interacted with accordingly.

And yes I've tried googling a variety of things, using them, but I'm not sure I'm using the right terms to get anywhere with it. I'm hoping that someone can point me in the right direction at least, and it'd be the icing on the cake if I was actually shown how to do it with this sample. I hope this is enough information, I'm just needing a general example of how to make this work.

Also, I can't find an interactive tag to put on this question so if someone can do that, it'd be great. :)

Edit 01: To be super clear, I'm asking how to make a terminal appear on the desktop via a scheduled script in crontab which runs the script called in crontab.

Edit 02: I'll post this info since it's being asked for, but I like doing things for the sake of the challenge and I'm not looking for a super specific answer. A general how to would be nice to know actually, rather than something specific only to this. However, I initially became concerned with this was I had put this line

sudo openssl req -x509 -newkey rsa:2048 -nodes -keyout /home/drawpileuser/key.pem -out /home/drawpileuser/cert.pem -days 365

into a script to create a self signed certificate for a collaborative drawing program. I wanted to make it accessible to non-tech savvy people to install Drawpile, so I made this super massive script. Though I've since been able to correct that issue by embedding the necessary information into the generated script with

sudo openssl req -x509 -newkey rsa:2048 -nodes -keyout /home/drawpileuser/key.pem -out /home/drawpileuser/cert.pem -days 365 -subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$unitname/CN=$hostname/emailAddress=$email"

Since I've done that, what I'm now attempting to do is make an easy to use script that on How to install EmulationStation for Raspberry Pi on Raspbian, which runs these commands by doing the first part, and then running the second part after the restart automatically. It then shows the script so it's apparent that work is being done. Nothing fancy here, just knowing that something is going on. I'm also assuming, perhaps incorrectly, that some commands at some point will not be able to be done without user interaction, hence the question of just timing a script to come up on its own with the terminal.

Edit 03 & Answer: User gf_ was able to point me in the right direction. By using the command lxterminal -e command ( Source ), I can make the terminal open a new window. But that's not all that needs to be done( Source 2 ). Specify the path rather than rely on environment variables in crontab... and I was already using PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin so I just went with that. Then create a simple script to use in crontab, which calls another script.

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export DISPLAY=:0.0
lxterminal -e /home/pi/Public/./test

Crontab (command crontab -e) ends up looking like...

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
* * * * * /home/pi/Public/test2

Which calls the final script test.

#!/bin/bash
echo 'This is a test.'
echo 'This is a written test with lxterminal -e for real.' >>     /home/pi/Public/testwrite.txt
sleep 10
  • Could you elaborate on the user interaction needed? – gf_ Oct 21 '17 at 12:41
  • Sure, I just didn't think the type mattered as it gets to be overly involved with some of the stuff I've tried writing. See above. – Wade S Oct 21 '17 at 12:59
  • Thanks, but sorry, I still fail to see how the user does need to interact with your script. Is he/she supposed to fill in email etc. for the cert? If not, could you please clearly state what the user is supposed to be going? – gf_ Oct 21 '17 at 16:03
  • Without the part at the end as in the second example, there are seven questions that need to be answered by the end user. But I'm not looking for help with a specific example. I want a general answer, can a script be scheduled to run and pop up in a terminal in the foreground? If not, no is a perfectly acceptable answer as well. – Wade S Oct 21 '17 at 22:15
  • "I want a general answer, can a script be scheduled to run and pop up in a terminal in the foreground?": If I do understand you correctly: sure. This question seems to ask the same. – gf_ Oct 21 '17 at 22:31
0

You can combine several bash commands by grouping them with { }

If you want to add a new task to crontab then you need to combine the current crontab config and the new task config. After that send this output as new config to crontab:

{crontab -l 2>/dev/null; echo "* * * * * /home/pi/Public/test2"} | crontab -
  • Alright, but that still doesn't really answer the core question at hand here. I'm asking how to make a terminal appear on the desktop via a scheduled script in crontab. – Wade S Oct 21 '17 at 12:37
  • Also, your version of that command is not desirable. As it puts in a } bracket at the end of the line in the crontab and it also removes any other existing entries in crontab. I'm not looking to nuke the existing information in there. (crontab -l 2>>/dev/null; echo "* * * * * /home/pi/Public/test2") | crontab works better for my purposes. – Wade S Oct 21 '17 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.