bash reboot command not found - bash

I am trying to execute a script on server. When I do crontab -l I get #reboot cd my_project_path; ./start.sh on terminal.
However when I do #reboot cd my_project_path; ./start.sh I get -bash: #reboot: command not found. How do I include reboot command in bash? Sorry if this is a very basic question, but I am not master in bash.

There isn't a command #reboot. I think you're looking for
shutdown -r now
or (possibly)
/sbin/reboot
which will reboot your machine. However, in crontab a #reboot is a scheduled time, so that's the command it would run when your system has just rebooted... so perhaps you really just wanted
cd my_project_path; ./start.sh

#reboot in crontab means "Do that / execute that on server boot"

Related

How to automatically start your docker services on the restart of my computer?

I want to write a bash script file (.sh) file in Ubuntu so that docker services start automatically on reboot.
User the cron service.
You need to use special string called #reboot. It will run once, at startup after Linux reboots. The syntax is as follows:
#reboot /path/to/job
#reboot /path/to/shell.script
#reboot /path/to/command arg1 arg2
#So to run docker on reboot:
#reboot start docker
This is an easy way to give your users the ability to run a shell script or command at boot time without root access. First, run crontab command:
$ crontab -e
OR
# crontab -e -u UserName
# crontab -e -u vivek
So, to run a script called /home/vivek/bin/installnetkit.sh
#reboot /home/vivek/bin/installnetkit.sh

`notify-send` works when invoking script manually, but not from a crontab

I wanted my cron job to report to me on desktop when it executes, through notify-send command on Ubuntu. I've read through the common problems that stated a shell script didn't have access to a display, which is solved by adding this before calling notify-send:
export DISPLAY=:0.0
So i am okay in that regard.
The place where i am right now, is that my script works and notifies me on desktop if i invoke it from terminal manually, but not from the crontab.
The situation is as follows:
The script that executes is a PHP file. The PHP command to invoke the shell command, is:
<?php
`export DISPLAY=:0.0 && command -v notify-send && notify-send "Hello world"`;
(backticks in PHP mean execute in shell)
In both cases i am running it as root
When testing from terminal, i run:
sudo -u root /usr/bin/php -q /var/www/html/cron.php &> /dev/null
This works, and i get a desktop notification
To edit my crontab for the root user, i use:
sudo -u root crontab -e
In my crontab file, my line is this:
* * * * * /usr/bin/php -q /var/www/html/cron.php &> /dev/null
This one does not produce a desktop notification, even though the script 100% executes (i have the successful result in log files).
What goes wrong here, and why wouldn't i get the desktop notification?
you must set the PATH within the script or export it from crontab!
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Raspbian - Transmission torrents don't start after rebooting

I wrote a bash file and put in cron to start my torrents (on web interface) automatically after rebooting the system, but nothing happens.
The crontab -e
#reboot bash /home/pi/torrent.sh >> /home/pi/torrent.log 2>&1
torrent.sh
echo
date
sudo service transmission-daemon start
sleep 10
sudo transmission-remote -t all -s
sleep 1
The torrent.sh has got all permissions.
P.S.: If I run the script from terminal my torrents start normally.
Hope you can help!

Why does following command work in the bash but not from script

I'm experiencing this really weird issue which I just can't understand why it is happening. When I execute following command from my shell manually it works.
sudo -u some-user echo "$SSH_KEY" | /home/some-user/.ssh/authorized_keys
however from a bash script it fails with a message we don't have any permissions.
#!/bin/bash
sudo -u some-user echo "$SSH_KEY" | /home/some-user/.ssh/authorized_keys
Is there any bash option to configure, or can someone explain this behavior?
It looks a bit like a bash security thingy for non interactive terminals or something like that, but I lost my creativity to google for the solution.
I'm running Ubuntu 16.04.
After hours of investigation it seems sudo commands where not executed because of the password prompt which does not occur from the script.
The solution was to first run a sudo command before runnning the script or just runnning the whole script as sudo so you can enter the password one time and the other sudo commands are running without password prompts.

why my svn backup shell script, works fine in terminal, but fails in crontab?

I have a svn backup script in a redhat linux. let's it called svnbackup.sh
It works fine, when I run it in terminal.
But when I put it into crontab, it will not bring the svnserve back, even the data is backuped correctly.
What's wrong with me???
killall svnserve
tar -zcf /svndir /backup/
svnserve -d -r /svndir
Usually, 'environment' is the problem in a cron job that works when run 'at the terminal' but not when it is run by cron. Most probably, your PATH is not set to include the directory where you keep svnserve.
Either use an absolute pathname for svnserve or set PATH appropriately in the script.
You can debug, in part, by adding a line such as:
env > /tmp/cron.job.env
to your script to see exactly how little environment is set when your cron job is run.
If you are trying to backup a live version of a repository, you probably should be using svnadmin hotcopy. That said, here are a few possibilities that come to mind as to what might be wrong:
You've put each of those statements as separate entries in your crontab (can't tell from the Q).
The svnserve command takes a password, which cron, in turn, cannot supply.
The svnserve command blocks or hangs indefinitely and gets killed by cron.
The command svnserve is not in your PATH in cron.
Assuming that svnserve does not take a password, this might fix the problem:
#! /bin/bash
# backup_and_restart_svnserve.sh
export PATH=/bin:/sbin:/usr/bin:/usr/local/bin # set up your path here
killall svnserve && \
tar -zcf /svndir /backup/ && \
svnserve -d -r /svndir >/dev/null 2>&1 &
Now, use "backup_and_restart_svnserve.sh" as the script to execute. Since it runs in the background, it should hopefully continue running even when cron executes the next task.

Resources