cron job error : "sqoop command not found" [duplicate] - cron

This question already has answers here:
How to get CRON to call in the correct PATHs
(15 answers)
Closed last year.
After installing sqoop successfully, i wrote a script "sqoop.sh" and kept in another folder. In terminal, I am able to execute sqoop script by giving command ./sqoop.sh. It works fine. Now when i try to add a cronjob of this, error message "sqoop command not found".
Here is sample -
45 * * * * /home/user/Desktop/hadoop/sqoop/sqoop_script/sqoop.sh

You can add the location of Sqoop's bin directory to the PATH. For example, when using bash shell, you can add these lines to the .bash_profile.
export SQOOP_HOME=/usr/hdp/current/sqoop-client
export PATH=$PATH:$SQOOP_HOME/bin

Related

Can't get Crontab jobs to work at all [duplicate]

This question already has answers here:
CronJob not running
(19 answers)
Closed 4 years ago.
New to Crontab use, I am trying to get a simple bash script to run.
add_temp:
#!/bin/bash
rnd1=$RANDOM
range1=20
let "rnd1 %= $range1"
rnd2=$RANDOM
range2=50
let "rnd2 %= $range2"
echo $rnd1
echo $rnd2
cd /var/www/html
sqlite3 test.db <<EOF
INSERT INTO temps (date, temp) VALUES ($rnd1, $rnd2 );
EOF
crontab -e:
SHELL:/bin/bash
* * * * * /var/www/html/add_temp
This doesn't seem to run at all. Works fine if run manually with /var/www/html/add_temp.
My guess is that the sqlite3 is not found when the cron daemon run the script.
You could modify the script and provide the full pathname of this command. Use a terminal to display the full pathname of the command:
type sqlite3
The cron daemon which will run the script does not have the exact same environment than the bash login shell used to run manually the script.
The variable that is usually differently set is PATH.
The first step to troubleshoot this situation is to compare the environments and debug the script.
I suggest to insert these lines below, after the very first line of the script
env
set -x
Run the script manually and redirect output, from a terminal:
/var/www/html/add_temp >/var/tmp/output_m.txt 2>&1
Change the crontab line for:
* * * * * /var/www/html/add_temp >/var/tmp/output_c.txt 2>&1
Wait that the cron daemon executes the script and compare the /var/tmp/output_m.txt and /var/tmp/output_c.txt files.
When the script will be fixed, remove the 2 debug lines from the script and restore the crontab original content.

Permission denied error when running crontab [duplicate]

This question already has answers here:
Running my program says "bash: ./program Permission denied" [closed]
(3 answers)
Closed 6 years ago.
I have created an r-script in the folder "csv_file"
marc#Marc-Linux:~/csv_file$ ls
8388.26580527145.csv csv_file.Rproj excel source write_csv2.R
Now I would like to create a crontab that executes this file every five minutes till 10am. Therefore I wrote the following
#open crontab
crontab -e
#add to file
*/5 10 * * * ~/csv_file/write_csv2.R
This however does not seem to work. That makes sense cause when I try to run
marc#Marc-Linux:~$ ~/csv_file/write_csv2.R
I get the following error:
-bash: /home/marc/csv_file/write_csv2.R: Permission denied
Any thoughts what goes wrong here?
make it executable first, using
chmod +x ~/csv_file/write_csv2/filename.r
and the execute it using ./filename.r

Crontab absolute path not working

I have a script to backup my database at /home/<user>/bin/dbbackup. The script is executable by all users, and owned by me. The files /etc/cron.allow and /etc/cron.deny do not exist.
In my crontab I have the following lines (including a new blank line after the last line of code):
#reboot /home/<user>/.dropbox-dist/dropboxd
30 2 * * * bash /home/<user>/bin/dbbackup
However, cron is not running my dbbackup script. When I run a manual test of the script it works. When I run this test on the command line: * * * * * /bin/echo "cron works" >> ~/file I get the following error:
No command 'dbbackup' found, did you mean:
Command 'dvbackup' from package 'dvbackup' (universe)
Command 'tdbbackup' from package 'tdb-tools' (main)
dbbackup: command not found
My server is running Ubuntu Trusty. Any help please?
As the comments noted, it appears that amiga_os needed remove the reference to bash in the line.
30 2 * * * bash /home/<user>/bin/dbbackup
Should be.
30 2 * * * /home/<user>/bin/dbbackup
I usually just call scripts from their path and use "#!/bin/bash" (or wherever your bash lives) as the first line of the script. It appears the amiga_os had already done this, which is good. I don't like putting sentences into cron because it makes me nervous.
I think it was a path issue as cron executes as the user but does not read the bash profile and therefore does not work exactly like it would under your shell as it might not have access to your $PATH.

how to run a bash script with multiple lines on crontab [duplicate]

This question already has answers here:
cronjob does not execute a script that works fine standalone
(3 answers)
Closed 6 years ago.
Because vpnc stopped every ~23 hours, I created a .sh file that is running as a cron job every 10 minutes, all that it does, is stop the vpnc process and run it again.
I have made it executable by chmod + x ping_vpnc.sh and it works fine when I run it from the terminal via ./ping_vpnc.sh
My file looks similar to:
#!/bin/sh
killall vpnc #just to make sure I don't create too many tunnels.
vpnc default.conf #run vpnc connect file.
my crontab file:
*/10 * * * * /home/username/ping_vpnc.sh
the problem with the script that it does't run fully, so it just kill the process without re-running it.
I'm running the script as root so I don't think that it's a privilege issue.
Any idea about why this is happening? I will appreciate it.
As indicated on comments, change
*/10 * * * * /home/username/ping_vpnc.sh
for
*/10 * * * * /bin/sh /home/username/ping_vpnc.sh
that is, tell crontab which binary has to execute the script.
For future references, let me point out the question you found in Ask Ubuntu: Script doesn't run via crontab but works fine standalone. It provides comprehensive information about the topic.

executing windows command line operation from python [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to call external command in Python
I want to execute a windows command line operation using python. To execute the command I have to go to a particular directory within my system and then execute the command.
for example
1) Go to a particular directory c:\some\directory
2) then use command somecommand -x -y
I saw some posts on this topic but I was not able to figure them out properly.
Thanks
I assume you want to change the working directory then execute a command. So:
os.chdir(DIRECTORY);
os.system(COMMAND);
os.chdir - Set the current working directory.
os.system - Execute a "system" command.
If setting the working directory is not required you could just specify the full path to os.system.
Also, you might want to check out subprocess as it might be more what you're looking for.

Resources