LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   running gpg to encrypt file from crontab (https://www.linuxquestions.org/questions/linux-security-4/running-gpg-to-encrypt-file-from-crontab-557172/)

aeby 05-28-2007 04:40 AM

running gpg to encrypt file from crontab
 
Hi there,

I have wriiten a bash script to encrypt a file using gpg, when i manually run it the script successfully encrypts the file, but when i put it in a cron it doesnt seem to work.
I am using RedHat 9.
I setup the cron usong crontab -e but still it didnt work, then i directly put it in the /etc/crontab file

my crontab looks like this

/etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
30 11 * * * root /1.sh > /tmp/ab.log

sample script

#!/bin/sh
/usr/bin/gpg --output /tmp/2.gpg --recipient greg --encrypt /letter

But the cron doesnt seem to work.

I am using gpg version 1.2.1

Please can anyone tell me what is wrong


Thanks in advance

~
~

ZAMO 05-28-2007 05:27 AM

hello,
Will you look into /var/log/cron. can you post your "tail -25 /var/log/cron" results here.

aeby 05-28-2007 06:39 AM

Hi,
Here are the last 20 lines of my cron.

May 28 12:01:00 arsha CROND[15108]: (root) CMD (run-parts /etc/cron.hourly)
May 28 12:53:00 arsha crond[15025]: (*system*) RELOAD (/etc/crontab)
May 28 12:54:50 arsha crond[15255]: (CRON) STARTUP (fork ok)
May 28 12:57:00 arsha CROND[15282]: (root) CMD (/tmp/2.sh)
May 28 12:58:19 arsha crond[15305]: (CRON) STARTUP (fork ok)
May 28 12:59:00 arsha CROND[15312]: (root) CMD (/tmp/2.sh)
May 28 13:00:19 arsha crond[15337]: (CRON) STARTUP (fork ok)
May 28 13:01:00 arsha CROND[15343]: (root) CMD (run-parts /etc/cron.hourly)
May 28 13:04:36 arsha crond[15374]: (CRON) STARTUP (fork ok)
May 28 13:07:00 arsha CROND[15381]: (root) CMD (/tmp/1.sh)
May 28 13:18:55 arsha crond[15898]: (CRON) STARTUP (fork ok)
May 28 13:19:06 arsha crontab[15901]: (root) LIST (root)
May 28 13:19:21 arsha crontab[15902]: (root) BEGIN EDIT (root)
May 28 13:19:25 arsha crontab[15902]: (root) REPLACE (root)
May 28 13:19:25 arsha crontab[15902]: (root) END EDIT (root)
May 28 13:19:26 arsha crontab[15904]: (root) LIST (root)
May 28 13:20:00 arsha crond[15898]: (*system*) RELOAD (/etc/crontab)
May 28 13:20:00 arsha crond[15898]: (root) RELOAD (cron/root)
May 28 13:20:08 arsha crond[15922]: (CRON) STARTUP (fork ok)
May 28 13:25:00 arsha CROND[15953]: (root) CMD (/tmp/1.sh > /tmp/ab.log)


i tried writing the log to abother file
25 13 * * * root /tmp/1.sh > /tmp/ab.log

but that file gives me nothing after the cron exceutes

i really dont know what the hell to do

aeby 05-28-2007 06:41 AM

[QUOTE=aeby]Hi,
Here are the last 20 lines of my cron.

May 28 12:01:00 arsha CROND[15108]: (root) CMD (run-parts /etc/cron.hourly)
May 28 12:53:00 arsha crond[15025]: (*system*) RELOAD (/etc/crontab)
May 28 12:54:50 arsha crond[15255]: (CRON) STARTUP (fork ok)
May 28 12:57:00 arsha CROND[15282]: (root) CMD (/tmp/2.sh)
May 28 12:58:19 arsha crond[15305]: (CRON) STARTUP (fork ok)
May 28 12:59:00 arsha CROND[15312]: (root) CMD (/tmp/2.sh)
May 28 13:00:19 arsha crond[15337]: (CRON) STARTUP (fork ok)
May 28 13:01:00 arsha CROND[15343]: (root) CMD (run-parts /etc/cron.hourly)
May 28 13:04:36 arsha crond[15374]: (CRON) STARTUP (fork ok)
May 28 13:07:00 arsha CROND[15381]: (root) CMD (/tmp/1.sh)
May 28 13:18:55 arsha crond[15898]: (CRON) STARTUP (fork ok)
May 28 13:19:06 arsha crontab[15901]: (root) LIST (root)
May 28 13:19:21 arsha crontab[15902]: (root) BEGIN EDIT (root)
May 28 13:19:25 arsha crontab[15902]: (root) REPLACE (root)
May 28 13:19:25 arsha crontab[15902]: (root) END EDIT (root)
May 28 13:19:26 arsha crontab[15904]: (root) LIST (root)
May 28 13:20:00 arsha crond[15898]: (*system*) RELOAD (/etc/crontab)
May 28 13:20:00 arsha crond[15898]: (root) RELOAD (cron/root)
May 28 13:20:08 arsha crond[15922]: (CRON) STARTUP (fork ok)
May 28 13:25:00 arsha CROND[15953]: (root) CMD (/tmp/1.sh > /tmp/ab.log)


i tried writing the log to abother file
25 13 * * * root /tmp/1.sh > /tmp/ab.log

cat /tmp/ab.log gives me an empty file with no contect after the cron exceutes

i really dont know what to do

ZAMO 05-28-2007 07:22 AM

please check the following
As log shows, it is running the job
1)check the script is ok( sh 1.sh)
If it is ok, check the path in crontab(seems to me, u r missing a / before root)
30 11 * * * /root/1.sh>/tmp/ab.log

All the best

aeby 05-28-2007 07:45 AM

Hi

The root in the above crontab is not in the path, it specifies that is is issued for the user root

Any more suggestions, if i take that out the cron doesnt execute


Thanks

ZAMO 05-28-2007 08:10 AM

oh... it is user root!!!! :)
But am getting the output.
its writing a file it /tmp
May 28 17:40:01 **** crond[6026]: (root) CMD (/root/1.sh > /tmp/ab.log)
May 28 17:41:01 **** crond[6032]: (root) CMD (/root/1.sh > /tmp/ab.log)

please the script

aeby 05-28-2007 09:47 AM

Hi,

what i am asking is only as part of a script i actually have to encrypt and transfer files between branches,

so the line of the script that i gave you is a test one for encrypting, i want the script to run from cron, i run the script from terminal maually it is fine,
but the script i mentioned above doesnt want to run form cron


the line of the script that does the encryption is this

gpg --output /tmp/2.gpg --recipient greg --encrypt /letter

i am just testing it takes a file under /tmp and encrypts it under /tmp just for testing purposes.


Thank for all the help, what to do now????

aeby 05-28-2007 09:49 AM

Hi,

i know that it is writing the crontab file /tmp/ab.log but it is not doing the encryption part in the script, the cron is working as per logs but it is not doing the encryption.

but when i run the script test.sh to encrypt it works fine

Aeby


All times are GMT -5. The time now is 04:41 AM.