How to run a script at the start up of Ubuntu? [closed] - shell

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to run some Java programs in the background when the system boots in Ubuntu. I have tried to add a script in /etc/init.d directory but failed to start a program. i.e programs are not started. What should I do for that?

First of all, the easiest way to run things at startup is to add them to the file /etc/rc.local.
Another simple way is to use #reboot in your crontab. Read the cron manpage for details.
However, if you want to do things properly, in addition to adding a script to /etc/init.d you need to tell ubuntu when the script should be run and with what parameters. This is done with the command update-rc.d which creates a symlink from some of the /etc/rc* directories to your script. So, you'd need to do something like:
update-rc.d yourscriptname start 2
However, real init scripts should be able to handle a variety of command line options and otherwise integrate to the startup process. The file /etc/init.d/README has some details and further pointers.

Related

Shell script cannot call some commands when starting up Ubuntu 16.04 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 12 months ago.
Improve this question
I am trying to run a set of shell scripts at login on a virtual install of Ubuntu 16.04.
I have added the shell scripts in ~/.bashrc and they load just fine, most of the script just run a few terminal commands, but one them calls in other programs – this script is the problem, it fails to see the program as installed "command not found".
When I run the same script from command line it works just fine.
Any guidance would be appreciated.
As pointed out above, my script was running before PATH was set. Adding the required PATH to the script allows it to run.
PATH = $PATH:<my_path>

How to make a command to launch a bash-script in mac terminal? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Basically, I want to be able to have a command for my command-line "Net", kinda like the "Python" command used to start python.
So I'd like to have a command like "Net" or something to start my bash-script, but I don't want to go into my .bash_profile and make an alias, I want it to be created automatically if you just run a script.
How would this be done?
It seems like you're looking for the install command...
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/install.1.html
install -m 755 ./my-bash-script.sh /bin/net
Just be sure use a directory that is in your $PATH and that you don't already have an executable file in your $PATH that is using the name of the command you plan to use. 'net' is an actual command used on linux systems, but I'm not sure about the Mac.
If you add it to your bash script, you might want to add some sanity checks...
#! /bin/bash
...
...
[[ ! -f /bin/$(basename $0) ]] && install -m 755 $0 /bin/$(basename $0)

What is difference .sh file to change executable (chmod +x) and not? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I notice when make a .sh file, usually, then we edit file's executable flag
$ chmod +x <sth>.sh
But without that executable flag, the .sh file can be executable.
$ sh ./<sth>.sh
why we need chmod?
Have a nice day!
By using chmod and turning on execute permissions, you can just run the file using
<sth>.sh
Without executable permissions, if you have read permissions you can still run scripts but you must use an interpreter, such as sh or bash
When you do
sh <sth>.sh
What this means is run the sh command, which reads the .sh file, and then interprets it, therefore you don't need execute permissions.
when you don't give the executable permission to the file , you have to mention with which binary you want to run your file .
for example you have to run file like
sh example.sh
but when you give the file executable permission you are allowed to run the file as ./example.sh

Shell script for installation [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I need a shell script file for Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support (LEMP) On Ubuntu 12.10. Can anyone direct me to create a shell script file to install these tools. Am new in creating shell script.
Your response should be appreciable!!!
Shell script is, basically, a file with commands you'd execute anyway by hand in command line.
Start with creating it, with the following contents:
#!/bin/bash
apt-get install ...
# do some other operations
Save it as script.sh. Now just change it's permissions, so it's executable:
$ chmod +x script.sh
Now it's ready to be invoked:
$ ./script.sh

Troubles with shell script versus terminal on Pi [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am trying to share a folder on a windows computer with the raspberry pi.
when I use these commands in terminal:
sudo mkdir -p /mnt/foldername
sudo mount -t cifs //IPADDRESS/folderIwanttoaccess/ -o username=usrname,password=passwrd /mnt/foldername
This works fine and I am able to save files on the raspberry pi to the windows shared folder.
but when I try this in a shell script I am able to see the folder as shared but with "^m" at the end.
for example: Foldername^M
Why does this happen and is there a way around to stop the "^m"?
Thanks in advance
According to this, you can sort your problem using sed, merely by using the following incantation: s/^M$//. Hope that helped!

Resources