Script working on command line and not on crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script working on command line and not on crontab
# 8  
Old 11-09-2017
Your problem seems to look like with java path.

is it autodirect or you have exported explicitly ?

Check this file:

more /usr/bin/hdfs
# 9  
Old 11-09-2017
Quote:
Originally Posted by beautymind
thank for the links sadique
The script works when I launch it on the command line and I don't have this credential problem , the same user ( who is me ) when I try to run it on crontab I get this error !!!
I believe cron jobs start with a reduced environment. I would guess that you either have "logged in" to something prior to running the script, or there is a setting in your .profile or .bashrc file that allows your script to be run from the terminal. This probably won't work, but try prefixing your command line (within the crontab) with /usr/bin/env (example):
Code:
30 40 * * * /usr/bin/env myscript arg1 arg2

Andrew
This User Gave Thanks to apmcd47 For This Post:
# 10  
Old 11-09-2017
Quote:
Originally Posted by beautymind
Here is the code :

Code:
for file in $FILE_LIST
       
 do
                /usr/bin/hdfs dfs -put -f $source_directory/$file $hdfs_target_directory
                res=$?
                       if test "$res" != "0"; then
                            echo "the hdfs put command failed with: $res"
                       else
                            echo "the hdfs put command success with : $res"
                       fi
        done


try below:

Code:
hdfs dfs -put -f $file $hdfs_target_directory

# 11  
Old 11-09-2017
more /usr/bin/hdfs returns :

Code:
#!/bin/bash
  # Reference: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
  SOURCE="${BASH_SOURCE[0]}"
  BIN_DIR="$( dirname "$SOURCE" )"
  while [ -h "$SOURCE" ]
  do
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
    BIN_DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd )"
  done
  BIN_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  LIB_DIR=$BIN_DIR/../lib

# Autodetect JAVA_HOME if not defined
. $LIB_DIR/bigtop-utils/bigtop-detect-javahome

export HADOOP_LIBEXEC_DIR=//$LIB_DIR/hadoop/libexec

exec $LIB_DIR/hadoop-hdfs/bin/hdfs "$@"

---------- Post updated at 08:23 AM ---------- Previous update was at 08:12 AM ----------

Even when I add /usr/bin/env it doesn't work.

To use Hadoop command you need to use kinit command to get a Kerberos ticket first, this kinit is generated automatically for me ( in the command line) but krontab ignores this .
My question is how to inform krontab so it considers this ticket ??
# 12  
Old 11-09-2017
Quote:
Originally Posted by beautymind

To use Hadoop command you need to use kinit command to get a Kerberos ticket first, this kinit is generated automatically for me ( in the command line) but krontab ignores this .
My question is how to inform krontab so it considers this ticket ??
I don't understand what you meant by the above (in red). Do you run kinit on the command line?

As I said earlier, your interactive environment and your cron environment are different. Your active tickets will not be available in the cron environment.

I think you need to save the kerberos ticket in such a way your script can pick it up, using kinit (which is not present in your script). I think your best bet is to google for how to do this.

Andrew
# 13  
Old 11-09-2017
@Andrew

"I think you need to save the kerberos ticket in such a way your script can pick it up, using kinit"

I think that if I can do that , I resolve the problem , but how can I do ?? Smilie
# 14  
Old 11-09-2017
Also try sourcing your .profile in crontab:-
Code:
30 40 * * * . ~/.profile 1>/dev/null 2>/dev/null; myscript arg1 arg2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed working on command line but file unchanged when execute with Shell script

I have a simple task to replace unix line feed end of line characters with carriage returns. When I run the following “change file in place” sed instruction from the command line all the Line feeds are successfully replaced with Carriage returns. sed -i 's/$/\r/' lf_file.txt But that same... (1 Reply)
Discussion started by: hawkman2k
1 Replies

2. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)
Discussion started by: ash1234
1 Replies

3. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (6 Replies)
Discussion started by: ash12345
6 Replies

4. UNIX for Dummies Questions & Answers

Script is not longer working in the crontab

This is the crontab it is supossed to be running everyday but it didnt 5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK,... (6 Replies)
Discussion started by: alexcol
6 Replies

5. HP-UX

rcp command is not working in crontab

Dear Friends, I am trying to copy SAP log file from one HPux server1 to another HPux server2 remotely through one script. following command has written in the script. rcp -rp /oracle/PRD/sapreorg/*.dbf oraprd@drsite:/oracle/PRD/sapreorg Above command working fine from command mode.... (5 Replies)
Discussion started by: BPANDEY
5 Replies

6. Shell Programming and Scripting

Script not working in crontab

Hi I have created a script. Which i have configured in cron to make it run in every 2 min. But script is not running. If I checl the cron log at /var/cron/log .it shows its running in every 2 min. Below is the command which i configured in crontab. But I am not able to find the way so that... (9 Replies)
Discussion started by: nandan8a
9 Replies

7. Shell Programming and Scripting

My script stops working when using crontab

I have made a shell script(/bin/sh) that starts a perl script (that I haven't made my self) that's starts a ssh session. The ssh session uses a private/public key to login so no password is needed. The Perl script works perfect. But when I put it in a cronjob (crontab) the ssh connection asks... (6 Replies)
Discussion started by: splinter_cell
6 Replies

8. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

9. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

10. UNIX for Advanced & Expert Users

crontab command not working

Dear Friends, I have tried to fire a job on daily basis through crontab command but it willn't work. i have given in the following manner: 07 19 * * * exp /user_name/passwd/ file = /path/file-name full = N owner = user-name but it is giving error that permission denied. i have checked that... (8 Replies)
Discussion started by: digant
8 Replies
Login or Register to Ask a Question