LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-28-2007, 04:40 AM   #1
aeby
Member
 
Registered: Mar 2007
Posts: 109

Rep: Reputation: 15
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

~
~
 
Old 05-28-2007, 05:27 AM   #2
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
hello,
Will you look into /var/log/cron. can you post your "tail -25 /var/log/cron" results here.
 
Old 05-28-2007, 06:39 AM   #3
aeby
Member
 
Registered: Mar 2007
Posts: 109

Original Poster
Rep: Reputation: 15
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
 
Old 05-28-2007, 06:41 AM   #4
aeby
Member
 
Registered: Mar 2007
Posts: 109

Original Poster
Rep: Reputation: 15
[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
 
Old 05-28-2007, 07:22 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
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
 
Old 05-28-2007, 07:45 AM   #6
aeby
Member
 
Registered: Mar 2007
Posts: 109

Original Poster
Rep: Reputation: 15
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
 
Old 05-28-2007, 08:10 AM   #7
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
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

Last edited by ZAMO; 05-28-2007 at 08:16 AM.
 
Old 05-28-2007, 09:47 AM   #8
aeby
Member
 
Registered: Mar 2007
Posts: 109

Original Poster
Rep: Reputation: 15
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????
 
Old 05-28-2007, 09:49 AM   #9
aeby
Member
 
Registered: Mar 2007
Posts: 109

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
encrypt and decrypt using encrypt(char block[64], int edflag) rockwell_001 Linux - Security 3 08-30-2009 09:16 AM
running dynebolic and forgot to encrypt my nest , now someone hacked in can't log int firedancer Linux - Newbie 1 05-14-2007 12:06 PM
GPG wont encrypt file. acidblue Linux - Software 3 05-07-2006 05:05 PM
How to encrypt a password to the /etc/shadow file? Milosevic Linux - Newbie 2 12-13-2005 02:14 PM
GPG encrypt text in terminal max-ebb Linux - Security 3 10-06-2004 06:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration