Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

#!/bin/bash
# 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.

EDIT

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.

share|improve this question
    
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. –  Cristian Ciupitu 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. –  Mike McMahon 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. –  Cristian Ciupitu 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! –  Mike McMahon 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)?. –  Cristian Ciupitu May 1 '12 at 17:59

2 Answers 2

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.

share|improve this answer
up vote 0 down vote accepted

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

#!/bin/bash
# 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 ;)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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