I have a file located on my linux box that is generated by a python script, the file is dropped inside of the /root/ directory

My bash script looks like so:

# Run the HR Data feed
cd /root/hr-feed
# the file created here will land one directory above the scripts in /root/
python main.py     

# Transfer the file to the server
cd /root/
smbclient \\\\[SERVER]\\[SHARE] --workgroup=[WRKGRP] --user=[USR] [PASS] -c 'put HRDataFeed.txt'

Everything works as desired up to the last line. It must be executing with an error (though I'm not quite sure how to figure out what that error might be).

This job is running from the crontab. Which as I understand runs in a slightly different environment than root (or at least it seems to with how it behaves).

If I execute the script directly (not from the crontab) it runs without a hitch and the file is transferred to the destination windows server box. My guess is that maybe I need to supply the full path to the HRDataFeed.txt file as part of the put command; however, I cannot seem to figure that out.

smbclient .... -c "put /root/HRDataFeed.txt"

results in an error that the file /root/HRDataFeed.txt cannot be found.

Any input is greatly appreciated.


I tried updating my crontab to read (for the sake of testing i had it running every minute)

          • /root/hrdatafeed > last_run.txt

However nothing ever seemed to land in the file.

I will try just adding a pipe directly to the SMBClient command.

  • Are you using SELinux? If so, you could disable it temporary with setenforce 0 and then re-enable it with setenforce 1. By the way ausearch --start recent will tell you recent SELinux denials. Regarding error logging, you could also redirect the stdout and stderr of smbclient to some files. Apr 28 '12 at 5:09
  • Thanks @CristianCiupitu I am on Ubuntu server, i believe it is Hardy. I had tried redirecting the output to some files, but i don't think I did it correctly. I'll update my question. Apr 28 '12 at 5:13
  • 1
    You need to redirect both stdout and stderr and maybe you should have also used an absolute path for the "log". Try /root/hrdatafeed >/root/last_run.txt 2>&1 or /root/hrdatafeed >/root/stdout.txt 2>/root/stderr.txt. Apr 29 '12 at 3:35
  • @CristianCiupitu thanks for all your help, you should make yours an answer. Helped me to diagnose and get it working! Apr 30 '12 at 17:41
  • There's no need; the important thing is that you've solved your problem. By the way In SF, when should a response be submitted as a comment and instead of an answer (and vice-versa)?. May 1 '12 at 17:59

Cron tries to send a mail (using /usr/bin/sendmail) when a command fails -- that's the only way I know of to get the actual output of the script (you could install sSMTP to get this working fairly easily). The main difference in the cron environment is usually $PATH, so try setting an appropriate PATH in the crontab which includes the directory where smbclient is.


I ended up slightly re-writing the script to read like so:

# Run the HR Data feed
cd /root/hr-feed
python main.py

# Transfer the file to the server
cd /root/
/usr/bin/smbclient \\\\[SERVER]\\HRDataFeed --workgroup=[WRKGRP] --user=[USR] [PASS] -c 'put HRDataFeed.txt'

I changed my crontab to this:

          • sh /root/hrdatafeed.sh > /root/last_run > 2>&1

Finally was able to get some meaningful messages in the last run file. Though there were no errors, I assume it was because I made the change to setting the full path to the smbclient command.

Thanks for all of the help on getting this worked out.

Now of course i'll update the cron tab to run with a little less frequency ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.