I have installed cgminer in my machine and could able to start it without any issues
when running ./cgminer in terminal.
But for a specific feature, i am trying to invoke the cgminer from
using shell script via a cron job.
1) The cgminer command executes correctly when i run the shell script
2) But it is not executing when i set the shell script as a cron job.
Below is the content in the shell script.
#!/bin/bash
export DISPLAY=:0.0
/root/test/cgminer/cgminer/cgminer >> /home/balan/temp/script/log.txt;
Please suggest.
Are you running this as a cronjob under the root user or the balan user? Since the cgminer binary is in the root directory this probably needs to run as root.
If you are running as root, try redirecting the error output and see what errors are being logged:
/root/test/cgminer/cgminer/cgminer >> /home/balan/temp/script/log.txt 2>/home/balan/temp/script/error_log.txt;
Solution :
The variable TERM has to be set as like below and respective host, username and password
to be given for the cgminer to execute from cronjob.
export TERM=xterm
#Change the below cgminer path - IMPORTANT
/root/test/cgminer/cgminer/cgminer -o $host -u $user -p $password
Related
I'm running a script from crontab in which I want to set the symbolic link for npx. It does some other things which are dependent on the npx command itself. Its running the script as expected on the giving time interval, but its giving me no result for command which npx or whereis npx. When I try to run the script from terminal directly these commands does generate the correct path.
Note that, crontab I'm using is under the root user privilege, i.e set with sudo crontab -e and verified with echoing whoami inside the script which generate 'root')
By default, crontab will run your cron jobs using sh which might be the reason you are getting no results.
Try to explicitly change the shell to your default shell by adjusting the crontab entry:
*/30 * * * * /bin/bash -c "/my_script.sh"
In this case I changed it to bash, you can change it to your desired shell.
I'm trying to create an EC2 User-data script to run other scripts on boot up. However, the scripts that I run fail to recognize some commands and variables that I'd already declared. I'm running the commands as the "ubuntu" user but it still isn't working.
My user-data script looks something like this:
export user="ubuntu"
sudo su $user -c ". ./run_script"
Within the script, I have these lines:
THIS_PATH="/some/path"
echo "export SOME_PATH=$THIS_PATH" >> ~/.bashrc
source ~/.bashrc
However, the script can't run SOME_PATH/application, and echo $SOME_PATH this returns a blank line. I'm confused because $SOME_PATH/application works when I log into the EC2 using SSH and my debug logs using whoami returns "ubuntu."
Am I missing something here?
Your data script is executed as root and su command leaves $HOME and other ENV variables intact (note that sudo is redundant). "su -" does not help either
So, do not use ~ or $HOME but full path /home/ubuntu/.bashrc
I found out the problem. It seems that source ~/.bashrc isn't enough to restart the shell -- the environment variables worked after I referenced them in another bash script.
Hi i have created a batch file (run.bat) that after execution connects me to UNIX server with help of plink. But issue starts from this point i have to execute a script after connection to my server the script contains a command sudo -l. After the execution i get the error as mentioned in subject can anyone help me on this issue ??
Batch File-:
"C:\Program Files\PuTTY" plink -ssh -pw Tos#12Ts w44dvftyw#caa1607UX009.wvd.abcd.net /opt/sieb/w44dvftyw/run.sh
Script file(run.sh) -:
#!/bin/bash
sudo -l
It says
sudo: command not found
But when i run my script normally on UNIX server it runs with no issues. What am i missing here to make it work this way please help.
Scripts such as ~/.profile or ~/.bash_profile responsible for setting up the current user's PATH are run only on login shells.
Running sh -c 'somescript' (as performed by ssh host 'somescript') is neither a login shell, nor an interactive shell; thus, it does not gain the benefit of such scripts.
This means that additions to the PATH (in your case, /usr/local/bin) may not be present with commands run in this way.
Among your options:
Pass the PATH you want as part of the command to remotely run. This might look like:
plink -ssh user#host "PATH=/bin:/usr/bin:/usr/local/bin /opt/sieb/w44dvftyw/run.sh"
Embed a working value in the script you're running:
#!/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
# ...put the rest of your script here.
I am trying to have my Ubuntu 12.04 LTS server run a bash script I have to start a Minecraft server on start up, prior to log in but as user minecraft. I can have it run as root by placing the following in /etc/rc.local
bash /path/to/script/script.sh
which runs the script as root, I have tried the following in /etc/rc.local
su -c `bash /path/to/script/script.sh` minecraft
but to no avail. Can anyone tell me what I am doing wrong or should be doing instead? The first line of my script is
#!/bin/bash
in case it is important. Thanks much!
Try
su minecraft -c '/bin/bash /path/to/script/script.sh &'
The user should be the first argument to su.
You should use quotes and not ticks for the command argument (-c)
You may want to consider using su -l minecraft to have the script run in an environment which would be similar to that if the user minecraft logged in directly.
Give this a shot and let me know if it works.
This works fine when I run it by hand:
#!/bin/bash
eval `ssh-agent`
ssh-add
/usr/bin/scp me#server:~/file ./
exit 0
However, when the cron runs the file is never touched. I know the ssh keys are right - replace that scp with an ssh and it runs fine.
You also might consider using rsync for this process instead of scp'ing the file as a cron script.
cron generally is run as root, have you tested this script as root to ensure that the ssh keys are in the correct location that root looks for? Or do you have your sshkeys in your user profile?
Not sure what version you are running, but in Snow Leopard cron jobs run as the user (check with whoami in your cron'd script) ... at least when the user is currently logged in.