Automate scripts

namz5659

New Member
Joined
Sep 12, 2018
Messages
8
Reaction score
2
Credits
0
Hi i have a Ethereum node running and mining on a terminal in linux. i want to create a script that will start up the node.sh roughly 2 minutes after startup. my scripts is in the home/chainskills/private/startnode.sh. i want this to be executed after startup. I have barely any knowledge of linux. Please help me. i was told to go and create a script in the etc/init.d directory but i dont know how to. i am running this on a ubuntu 18 on a mini-mac.
 


Hi @namz5659, and welcome! I have deleted your duplicate post to avoid confusion. I'm at work right now but will try to help look for a solution to your question, but perhaps others will offer you some advice before I can return.

Cheers
 
Hi i have a Ethereum node running and mining on a terminal in linux. i want to create a script that will start up the node.sh roughly 2 minutes after startup. my scripts is in the home/chainskills/private/startnode.sh. i want this to be executed after startup. I have barely any knowledge of linux. Please help me. i was told to go and create a script in the etc/init.d directory but i dont know how to. i am running this on a ubuntu 18 on a mini-mac.
Hi again... sorry I could not get back to you sooner. Working 12-hr shifts sometimes offers easy days, and sometimes not. :(

And since no one else has chimed in yet, let's try to see what we can do to get started. Since you're new to Linux, one thing you will quickly learn is that there is almost always more than one way to do anything. So I might start you off in one direction, then someone else with more knowledge and experience will hopefully set you straight! :D

In your opening paragraph, you seem to be saying that you want to create a script (startnode) to call up another script (node).... any particular reason for that? Why not just call up the script you want to run... node.sh... after your desired 2 minute delay?

You say your node is running and mining.... and I want to confirm that. Node.sh is, in fact, working properly.... right? One question that may come up is: Does node.sh need to run as root? That is, when you run this script, does it require a password to continue? And to be clear, does it need the root password or your user password (if they are different)?

Because you are dealing with a cryptocurrency application, I don't want to steer you wrong or have you make any mistakes that might compromise the security of your script. This stuff is way over my head. :eek::D I have just a little knowledge about running scripts at startup, or can figure stuff out from Google instructions, but you should definitely be thinking about security with this task. You may hear from @Rob or @JasKinasis or others who have far greater knowledge/skill than me. But your answers to my questions above may be helpful to them as well.

Okay, enough for now... I'm off to bed.

Cheers
 
HI, many thanks for taking the time to read and reply to my comment. my node is running and functioning properly. It requires the root password as it is the same for the user account. i have tried to use a cronjob but i was told that i have to usean alternative.( /etc/init.d/.
 
Hi one other thing regarding the node. i am very sorry for the misinterpretation. i only have a script called startnode.sh. This is the scripts that mines the blocks. i want to only run this after 2 mins of booting up. i need help creating a script that starts the startnode.sh "Why not just call up the script you want to run... startnode.sh... after your desired 2 minute delay?" - this is exactly what i want to do.
 
Hey there namz - welcome to the forum!

You could put a line in your cron starting with '@reboot' and it will start when the machine starts. You can call a script which you can start with a sleep for 2 mins if you like.

I created a script to build LTC nodes in the past - you might get some good info out of it for your uses.
https://gist.github.com/ltcnodes/b6cdda3952f8f90a88fbdae355c96716
 
You could write an init script (for /etc/init.d/ like you mentioned) but using cron gets the job done pretty easily w/o having to do all that. Is there an issue with using cron on your machine?
 
yes i have tried using cron multiple times and i have asked multipe forums but it never works. I have spoken to a person that deals with scripting and they told me that i would be better of using a init.d script. please advise me on how to do this. I will even pay money to get this done.
 
You could write an init script (for /etc/init.d/ like you mentioned) but using cron gets the job done pretty easily w/o having to do all that. Is there an issue with using cron on your machine?
Hi Rob, I am stuck could you please help me.
 
Ubuntu 18 uses systemd, so you're going to need to create a service - here's a pretty complete howto:
http://userscripts4systemd.blogspot.com/2016/07/easy-systemd-startup-and-shutdown.html

Otherwise, i'd suggest using cron as stated above.. much easier and we can help you troubleshoot if it's not working correctly.

You can test the cron one by creating a file on boot ..

Typing this command will add 'touch ~/test.txt' to your crontab:
crontab -l > /tmp/mycron ; echo "@reboot /usr/bin/touch ~/test.txt" >> /tmp/mycron ; crontab /tmp/mycron ; rm -rf /tmp/mycron

You can see the line in cron by listing out your crontab:
crontab -l

Then, reboot.. and see if ~/test.txt was created. ~/ is your home directory, so you should see it in there.

If that works, then we'd replace the "/usr/bin/touch ~/test.txt" portion with a pointer to your node startup script.
 
Hi rob, reclarifying this, the text file was not create that is why i want to use init.d to make my ethereum node startup 2 minutes exactly after bootup without cron.
 
Not to be blunt, but we're here to help point in directions to complete what you're looking to do, not create scripts for you..

If you'd like to troubleshoot why cron didn't create the file, you can look in the /var/log/syslog file and see what the error was.. if you want to go init script direction, you are running on systemd, so you'd likely want to create an init script as outlined in the link i shared above.

You can also throw a script in /etc/rc.local, but since ubuntu 16, you'd need to enable that with
'systemctl enable rc-local.service'
 
Hi one other thing regarding the node. i am very sorry for the misinterpretation. i only have a script called startnode.sh. This is the scripts that mines the blocks. i want to only run this after 2 mins of booting up. i need help creating a script that starts the startnode.sh "Why not just call up the script you want to run... startnode.sh... after your desired 2 minute delay?" - this is exactly what i want to do.
Hi again. I'm still confused by what I quoted above and put into Bold text. You have a script, but you want to create a new script to call the existing script... which is not necessary. Your final statement acknowledges (I think) that you only need your existing script, and that you want that script to start after a 2 minute delay. No need to make this any harder or more complicated than it already is.

I've actually spent a good deal of time trying to figure this out today, but I'm afraid I have not had much luck.... this isn't something that I've needed to do for myself so I have no experience at it. I'm using Mint which is similar to Ubuntu, and using crontab to create and delete a text file for testing works fine. I'm pretty sure that this test would work for you too if you create the crontab correctly. I've also managed to get a GUI application to start using crontab after much Googling. But, like you, I'm not getting my script to run from crontab. There are several things that can cause failures... path, permissions, environment variables, syntax.... but I have not hit the right combination.

@Rob's links also give good details and instructions on how to setup a systemd service that starts at boot time. I followed along with those also today but again did not have much luck getting my script to run there either. It's still my own inexperience, no doubt. The failure is likely the same as with crontab... path, permissions, etc.

I won't have much more time to spend looking for this though... back to work tomorrow, and other duties needing attention. The good thing is that your script works, even it you must start it manually.

Cheers
 

Members online


Latest posts

Top