newbie question... how can I get my script init script to start when linux boots. Can I just drop a script into the /etc/init.d directory and make manual links to rcX.d?
Thanks
The file /etc/rc.local is a good candidate for local jobs, and it avoids some of the complexity of using /etc/init.d/ and similar directories.
Just add a line to /etc/rc.local to launch your job.
Yes, you are right. You can read on this: http://www.cyberciti.biz/tips/linux-how-to-run-a-command-when-boots-up.html
Related
So I have this issue on archlinux with crontab. I have a python script which when run opens a webcam with detection AI. I have tried it outside of the crontab several times and it runs perfectly but when I try to schedule it and run with crontab I can't see webcam opening. I am guessing it might be because of the privileges of the crontab or maybe some dependencies. Any help is appreciated. Thanks all in advance.
When you run from shell, e.g. bash, it calls .bash_profile, which you might have setup some environment variables. Therefore, your webcam program work. To proof my point, rename the .bash_profile temporary to other filename, and it should fail in shell prompt like crontab as well.
If above is valid, then you need to add necessary environment variables into your program, e.g. shell script. This is a standard practice for all programs triggered by UNIX crontab
I want to run series of commands in bash shell file. But one of the command requires reboot of the system and I have added reboot command in the shell file. But after the reboot that process is lost. Is there any solution for this?
In the system the only thing that is really persistent is a file. That's pretty much what you should use.
Try making the part of the script that needs to be executed after reboot in to /etc/rc.local from within the script.
Reference
When I try to run a Perl script which is called via Linux script manually it works fine but not executable via CRON.
Linux_scrip.sh conatains Perl_script and the command is,
perl_path/perl Perl_script.pl
I got perl_path using which perl command.
Can anyone suggest why is it not executable via CRON entry.
Most likely suspects:
Current work directory isn't as expected.
Permission issues[1].
Environment variables aren't setup as expected.
Requirement of a terminal can't be met.
See the crontab tag wiki for more pitfalls and some debugging tips.
The first thing you should do is to read the error message.
This isn't likely to be an issue for you own cron job, but I've included it since it's quite a common problem for scripts run from other services.
Most probable cause is current working directory.
Before perl command execution, write a command to change directory.
Something like :
cd perl_path;
perl Perl_script.pl
I am creating a terminal program and cannot find out what the ending is for Linux. I know in windows it is .cmd. Any help would be great.
Thank you.
Yes, you can remove the .sh at the end and it should work, generally using ./cmd will get it to run. this goes for C programs as well. You do not need to give an extension for the object file, You could then add a path to your bash file and then you can execute it as a normal command.
Look here.
https://stackoverflow.com/a/8779980/2720497
You don't need a file extension on Linux, though typically, people use .sh (sh being short for 'shell').
You can run it one of two ways:
bash myscript.sh
or you can make the script itself executable and run it directly:
chmod a+x myscript.sh # make it executable
./myscript.sh # run it
Linux scripts' first line is typically #!/bin/bash which is the path to the specific shell used to run the script with the second method.
After researching, it seems that it would be easier to add commands to an existing script as opposed to creating a startup script for each of my needs. I am trying to get a series of repititive tasks done at system startup like:
sudo mkdir -p ~/scripts
sudo mount -t vboxsf scripts ~/scripts
Instead of finding a methodology for each system (I read that start script vary from system to system), I would like to know if there is a universal scripts to append this too (like I have done with environment variables in /etc/environment). Is there a universal file I can target to do these mounts?
Thanks, Yucca
some distributions (Redhat/CentOS) have /etc/rc.local exactly for this task. On openSuSE it is /etc/init.d/after.local
Take a look at initd
http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/