Script won't execute on crontab [closed] - linux

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 2 years ago.
Improve this question
I have a script which executes manually:
#!/bin/bash
mount -t cifs //192.168.138.18/Shared_Drive /mnt/share -o username=user,password=guest
But sudo crontab -e doesn't execute it. I tried:
#reboot /home/user/startup.sh
#reboot sh /home/user/startup.sh
#reboot bash -l /home/user/startup.sh
#reboot /bin/bash /home/user/startup.sh
Nothing works. Permits are:
-rwxr-x--x 1 user user

crontab -e doesn't execute scheduled command, it opens your crontab rules file in an editor
The command will then be executed by cron itself on the specified schedule. (If the rule is written correctly. If you want help checking that then include the cron rule.)
Also note that the crontab command man page says
Note that su(8) can confuse crontab and that if you are running inside of su(8) you should always use the -u option for safety's sake
So you should run sudo crontab -u root -e

Related

Bash script check permissions to run command on remote [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 4 years ago.
Improve this question
I have a local development machine and from my bash script am sending commands to the remote server.
How can I write bash code to check if I am allowed to run the remote command so that I can handle the success/failure response from my script?
Alternatively, how can I capture the output so that I can parse it and detect if it succeeded. The difficulty with parsing is that the ssh command might trigger a password prompt so I can't interfere with that.
That bash script uses ssh -qt to send the remote commands
Command
ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php"
Output:
[sudo] password for xxx:
Sorry, user xxx is not allowed to execute '/usr/local/bin/php /mnt/data/script.php' as www on host.domain.com
Assuming that user != root above: you can't - there's no way to read /etc/sudoers or /etc/sudoers.d/* in a normally set-up Linux box if you're not root, so apart from trial & error there's nothing to be done.
As for capturing the result - that's fairly simple (parsing it, of course, is a different story, depending on what you're doing over there).
output=$( ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php" 2>&1 )
After the execution (and you typing the password for sudo)
echo $? # gives you the return-code of what happened on the far end, if it's a success that should be 0
echo $output # gives you the strings to parse

Issue with changing login shell [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 6 years ago.
Improve this question
I want to change the default login shell on my Ubuntu.
To change the shell I ran the following:
$ chsh -s /usr/bin/zsh
After that I restart my terminal but my default shell is still bash.
$ echo $SHELL
/bin/bash
These are shells installed on my machine:
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/zsh
/usr/bin/zsh
Record for my user in /etc/passwd is also changed like expected:
$ cat /etc/passwd|grep myuser
myuser:x:1000:1000:myuser,,,:/home/myuser:/usr/bin/zsh
I successfully changed my login shell the same way on my mac but I seem to be having some issue on Ubuntu. Am I missing something here?
You need to logout and log back into Ubuntu so that your GUI based X terminal shells pick up the new shell value.
Note: Ctrl+Alt+F[1-6] represent 6 virtual shells while GUI login is on Ctrl+Alt+F7

How to set up an SSH Server on OS X [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 8 years ago.
Improve this question
I'm planning on making a Bash script that sets up an SSH server. The script is only meant to work on a computer running OS X. With the research I have conducted it seems like you have to use the GUI to enable SSH. Is their a way to enable SSH through Terminal and then create a script that does so?
You can enable it from the command line (or a shell script) with:
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
You might also want to regulate access to the ssh service with the com.apple.access_ssh group:
sudo dseditgroup -o edit -a usernametoallow -t user com.apple.access_ssh
sudo dseditgroup -o edit -a otherusernametoallow -t user com.apple.access_ssh
sudo dseditgroup -o edit -a groupnametoallow -t group com.apple.access_ssh
...after which only usernametoallow, otherusernametoallow, and members of groupnametoallow will be able to ssh into the Mac.

Bash Script continues after reboot? [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 8 years ago.
Improve this question
I´ve written a simple bash Script to reboot and update my Ubuntu 12.04 server automatically via crontab.
Here is my script:
#!/bin/bash
sudo reboot
/usr/bin/apt-get -qy update > /dev/null
/usr/bin/apt-get -qy dist-upgrade > /dev/null
exit 0
The update section doesn´t work. The server only restarts.
Can someone help me?
The script calls reboot first which halts execution so the update, upgrade is never called. If you want to reboot put it at the end of the script.
Piping the outputs to /dev/null is also a bad idea in case something goes wrong.
Better use something like this:
unattended-upgrades
It can notify you of the updates and problems and can also be configured to only perform security updates automatically
You can use cron's special word #reboot to run script after reboot. Edit your crontab with crontab -e to add:
#reboot apt-get --quiet --yes update > /dev/null && apt-get --quiet --yes dist-upgrade > /dev/null
# or
#reboot update-after-reboot.bash

Got an error while executing bash commands on remote ubuntu machine "no tty present and no askpass program specified" [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'm running a bash script to execute a command on a remote host. Here is the command:
ssh ppuser#10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"
$1 and $2 are command line arguments. But while executing I'm getting this error : no tty present and no askpass program specified.
Hope you will help me, any help would be greatly appreciated. Thank You.
Somewhere in your sudoers file you have following
Defaults requiretty
Just comment this line - remove it. Or
Defaults !requiretty
For specific program name you can also attempt following:
Defaults </path to program> requiretty
change it to
Defaults </path to program> ! requiretty
Specific to user you can add
Defaults:username !requiretty
Adding What already have been specified in comment,
For the same you will have to
user-name ALL=(ALL) NOPASSWD: ALL
Its for passwordless sudo
Looks like you are invoking sudo, and it is not working because it doesn't have a tty bound. add
"Defaults visiblepw"
in sudoers file enables sudo even if a console doesn't allocate a tty. Use visudo on the remote machine to add this and see if this helps.
Try this command
sshpasss -p password ssh ppuser#10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"

Resources