Using crontab...

I’m just trying to do crontab tasks.

First changed VISUAL variable to “nano” (I don’t know how to use vi…). Created task with “crontab -e”, tried this simple task and saved:
40 16 * * * ls
Verified the task:

user@linux-loyv:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.uDB3KV installed on Mon Dec  2 16:34:18 2013)
# (Cronie version 4.2)
35 16 * * * ls
You have mail in /var/spool/mail/user

System has never ever send me mail, and I didn’t like it… Anyway checked it:

user@linux-loyv:~> cat /var/spool/mail/user
From user@linux-loyv.site  Mon Dec  2 16:35:01 2013
Return-Path: <user@linux-loyv.site>
X-Original-To: user
Delivered-To: user@linux-loyv.site
Received: by linux-loyv.site (Postfix, from userid 1000)
    id 772E5C10B9; Mon,  2 Dec 2013 16:35:01 -0600 (CST)
From: user@linux-loyv.site (Cron Daemon)
To: user@linux-loyv.site
Subject: Cron <user@linux-loyv> ls
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/user>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=user>
X-Cron-Env: <USER=user>
Message-Id: <20131202223501.772E5C10B9@linux-loyv.site>
Date: Mon,  2 Dec 2013 16:35:01 -0600 (CST)

Downloads
Documents
Desktop
Pictures
Music
Templates
Public
VirtualBox VMs
Videos
bin
public_html

But the thing is, it seemingly didn’t work. I was expecting an actual displayed ls on my current directory at minute 40, but nothing happened.
What am I doing wrong? And how can I clear system mails?

Thanks.

On 2013-12-03 00:06, F style wrote:
>
> I’m just trying to do crontab tasks.
>
> First changed VISUAL variable to “nano” (I don’t know how to use vi…).

I use joe. I haven’t learned to use vi in about 15 years, except the
minimal to exit with save or no save.

> Created task with “crontab -e”, tried this simple task and saved:
> 40 16 * * * ls

Yes, but where would the output of ls go? crontab does not have a
terminal, thus the output would go to email.

> Verified the task:
>
> Code:
> --------------------
> user@linux-loyv:~> crontab -l
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/tmp/crontab.uDB3KV installed on Mon Dec 2 16:34:18 2013)
> # (Cronie version 4.2)
> 35 16 * * * ls
> You have mail in /var/spool/mail/user
> --------------------
>
> System has never ever send me mail, and I didn’t like it… Anyway
> checked it:

I’m sure it has sent the email.

>
> Code:
> --------------------
> user@linux-loyv:~> cat /var/spool/mail/user
> From user@linux-loyv.site Mon Dec 2 16:35:01 2013
> Return-Path: <user@linux-loyv.site>
> X-Original-To: user

See? you have email. And this is the output of your command:

> Downloads
> Documents
> Desktop
> Pictures
> Music
> Templates
> Public
> VirtualBox VMs
> Videos
> bin
> public_html
> --------------------
>
> But the thing is, it seemingly didn’t work.

It did work! It worked exactly as you ordered.

> I was expecting an actual
> displayed ls on my current directory at minute 40, but nothing happened.

Wrong expectations. :slight_smile:

Unless you specify where the output goes (it can not be a terminal), it
goes to an email to the local user.

> What am I doing wrong? And how can I clear system mails?

Use “mail”, “pine”, or “mutt”.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

Thanks you. But now I came with the real pain in the butt…
Look, I apologize beforehand because this is not exactly openSUSE related, but I need to get this to work soon and I need help…

My objective is to make automated backups from a remote server via ssh.
I’m practicing with 2 boxes: my host openSUSE box and my guest virtualized CentOS box, using VirtualBox.
My practice is pulling files from openSUSE box to CentOS box via ssh with an automated cront task.

So obviously I already have set public/private keys (a passphrase protected key) and added the identity to ssh-agent on CentOS, so scp command doesn’t ask for passphrase. I have already tested it and works indeed: using scp on CentOS box to pull from openSUSE box works without passphrase, even though it’s set.

So I proceeded, making a script named backup.sh on CentOS box with this:

cd /home/centosuser
cp test1 test2
scp suseuser@ipadress:/home/user/Documents/file1 /home/centosuser/file2

Then I set my crontab task:

10 20 * * * /home/user/backup.sh [Return key]

Where Return key means I tap Return key, it’s not written of course. Lines 1 and 2 are for a test that I’ll also explain. This would execute everyday at 20:10.
Then I save and wait for the moment of execution. When the moment comes, lines 1 and 2 are effectively performed, but scp line is not!

So then I tried moving scp line to the top, making it line 1, and did another crontab test. Result: the cp line was performed but not immediately, but after a little while. Which means there was a delay due to the scp line that came first. Scp line is doing something but is not doing it’s duty!

What am I doing wrong? Can you help me? Thank you.

On 2013-12-03 03:26, F style wrote:
>
> Thanks you. But now I came with the real pain in the butt…
> Look, I apologize beforehand because this is not exactly openSUSE
> related, but I need to get this to work soon and I need help…

If I can, I’ll help, don’t worry.

> My objective is to make automated backups from a remote server via ssh.
> I’m practicing with 2 boxes: my host openSUSE box and my guest
> virtualized CentOS box, using VirtualBox.
> My practice is pulling files from openSUSE box to CentOS box via ssh
> with an automated cront task.

Sounds good.

> So obviously I already have set public/private keys (a passphrase
> protected key) and added the identity to ssh-agent on CentOS, so scp
> command doesn’t ask for passphrase. I have already tested it and works
> indeed: using scp on CentOS box to pull from openSUSE box works without
> passphrase, even though it’s set.

Ok, good.

> So I proceeded, making a script named backup.sh on CentOS box with this:
>
> Code:
> --------------------
> cd /home/centosuser
> cp test1 test2
> scp suseuser@ipadress:/home/user/Documents/file1 /home/centosuser/file2
> --------------------

Aha.

> Then I set my crontab task:
>
> Code:
> --------------------
> 10 20 * * * /home/user/backup.sh [Return key]
> --------------------
>

Right.

> Where Return key means I tap Return key, it’s not written of course.

Yes, I understand :slight_smile:

> Lines 1 and 2 are for a test that I’ll also explain. This would execute
> everyday at 20:10.

That kind of test is typical, we all have done it with cron jobs :slight_smile:

Hint:


/bin/logger -t Mine -p syslog.info "Testing a message."

Then I save and wait for the moment of execution. When the moment comes,
lines 1 and 2 are effectively performed, but scp line is not!

Ah, I see… I have a guess. Maybe.

So then I tried moving scp line to the top, making it line 1, and did
another crontab test. Result: the cp line was performed but not
immediately, but after a little while. Which means there was a delay due
to the scp line that came first. Scp line is doing something but is not
doing it’s duty!

Then my guess is maybe wrong.

What am I doing wrong? Can you help me? Thank you.

Ok, first thing is look at your email. Not with thunderbird, but
something simple like “mail”. Try it. If you need something better,
install and use “pine” (aka alpine). Both by default are set to read the
system email, and cron jobs by default send all their output to the
email, so you must have a look in there.

The guess.

The environment in cron jobs is not the same one you get on a terminal;
for instance, path is not set. So instead of calling “scp” you have to
find out the path:


cer@Telcontar:~> which scp
/usr/bin/scp
cer@Telcontar:~>

and then your cronjob would be:


cd /home/centosuser
cp test1 test2
/usr/bin/scp suseuser......

Try that - but read your system email first.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I type “mail”, and I NEVER HAVE NO MAIL in CentOS box at all, WTF!?
Using scp’s path didn’t work neither.

After reading in some other forums I came with a remote suggestion: setting a passphrase-less key (so no more ssh-agent neither).
Did it, then modified backup.sh:

/usr/bin/scp suseuser@ipadress:~/Documents/file1 .

Set again time for the cron task, and this time worked!
But being even more curious, I modified again backup.sh by removing scp’s path, just leaving “scp suseuser@…”, and it worked as well!

W T F !! ??

Crontab is doing its job even without scp’s path, but even more, it’s only working for passphrase-less keys! Why? And I still have no mail…
Though, the other forums mentioned something about passphrase protected keys actually not being able to be read when using cron, as though cron still was asked for passphrase itself… But then what is ssh-agent for? It’d mean something like cron is caring bananas about ssh-agent!

On 2013-12-03 04:56, F style wrote:
>
> I type “mail”, and I NEVER HAVE NO MAIL in CentOS box at all, WTF!?
> Using scp’s path didn’t work neither.

I’m sorry, but I can not help there. I can only help you about cron in
openSUSE and corresponding email in openSUSE, or about scp in openSUSE.
About what happens on CentOS I can say nothing.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

OK, thanks for your attention anyway.

Regarding mail on openSUSE, perhaps you could help me with a thing. The only mail thing I have installed is “mailx”, from the man page. Is it the one used for checking mail? How can I clear/get rid of previous mails? For instance, the one I got on my very first cron attempt on openSUSE box…

Also, do you think it’d be worth trying this thread in another subforum? Like Network/Internet or Programming/Scripting ones… Or would I be warned for double post?

If you are working with openSUSE help is here. But we don’t know CentOS and there may be subtle differences

type man mail for the manual

On 12/02/2013 08:56 PM, F style wrote:
>
> I type “mail”, and I NEVER HAVE NO MAIL in CentOS box at all, WTF!?
> Using scp’s path didn’t work neither.

If you do not clear it out, and your system ever generates some, of course
you’ll have e-mail just as if you never logged into your regular e-mail
and you received some spam which was never magically cleaned out. Nothing
magical here. Why you have e-mail is up to you and your services on the
system (in this case, CentOS). If you do not like those messages, find
ways to prevent or delete those messages.

> After reading in some other ‘forums’
> (http://ubuntuforums.org/showthread.php?t=1594167) I came with a remote
> suggestion: setting a passphrase-less key (so no more ssh-agent
> neither).
> Did it, then modified backup.sh:
>
> Code:
> --------------------
> /usr/bin/scp suseuser@ipadress:~/Documents/file1 .
> --------------------
>
> Set again time for the cron task, and this time worked!

Sure it did. The problem isn’t cron.

> But being even more curious, I modified again backup.sh by removing
> scp’s path, just leaving “scp suseuser@…”, and it worked as well!

Cron is working, as you have shown. What is left? scp it would seem.

> Crontab is doing its job even without scp’s path, but even more, it’s
> only working for passphrase-less keys! Why? And I still have no mail…
> Though, the other forums mentioned something about passphrase protected
> keys actually not being able to be read when using cron, as though cron
> still was asked for passphrase itself… But then what is ssh-agent for?

I think we covered this in your other thread on ssh and ssh-agent last
week. The ssh-agent is for a specific user, which is the same for your
crontab (nice with ‘crontab -e’) but the ssh-agent is a wrapper process
that works with anything it holds. You know already that the GUI
environment can wrap anything within it from the other thread, but this
isn’t that scenario. The cron service runs completely separately from the
GUI, and from any single shell, and it is not wrapped by the ssh-agent,
and if it was, you’ve never typed your passphrase into the ssh-agent
within it because you have never run within a shell within cron.

You can see the process tree with the ‘pstree’ command, or maybe the ‘ps
auxf’ command. ssh-agent is for interactive sessions, and cron is not
interactive.

Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…

@ab:
So cron is completely independent from ssh-agent, and even bash? (In virtualized CentOS box I have no graphic interface, text mode only).
And if so, then it’d make sense what I found in other forums, saying that cron is actually having problems with the passphrase itself, and since with passphrase-less ssh-agent is not necessary…

Beforehand, thanks for showing up again, mr Ab!

P.S: I already apologized and I do it again for talking about a CentOS box here…

Just can’t give advice about CentOS unless you stumble on to someone that uses the OS here. And there well may be differences in the cron app that is used. These little things are what make different distros different

On 2013-12-03 06:26, F style wrote:
>
> @ab:
> So cron is completely independent from ssh-agent, and even bash? (In
> virtualized CentOS box I have no graphic interface, text mode only).
> And if so, then it’d make sense what I found in other forums, saying
> that cron is actually having problems with the passphrase itself, and
> since with passphrase-less ssh-agent is not necessary…
>
> Beforehand, thanks for showing up again, mr Ab!
>
> P.S: I already apologized and I do it again for talking about a CentOS
> box here…

No, it is not a matter of apologizing, no need to. What I mean, and it
is the same problem for others, is that I have never used centos, thus I
can not help you with a system I know nothing about. If someone here
knows about that system, then that person con help you on that side.

It is not because of offtopic or anything similar.

What I can say, is that if centos is similar to openSUSE, certainly cron
can never prompt you for a password. I would try your setup against
another openSUSE virtual machine and forget centos till you have it working.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On 2013-12-03 05:26, F style wrote:
>
> OK, thanks for your attention anyway.
>
> Regarding mail on openSUSE, perhaps you could help me with a thing. The
> only mail thing I have installed is “mailx”, from the man page. Is it
> the one used for checking mail? How can I clear/get rid of previous
> mails? For instance, the one I got on my very first cron attempt on
> openSUSE box…

The tool named “mail” in openSUSE is in fact also named “mailx”. or to
be precise, “mailx” is a modern and improved replacement for the
classical, unix like, plain “mail”.

If you have problems finding how to remove mails with it, then just use
“pine”. Just install it (do not delete mailx). Pine has menus, it is
TUI. It even responds to the mouse.

But, mind, this advice is for openSUSE, not for centos. I don’t know if
it is valid advice for centos or not.

> Also, do you think it’d be worth trying this thread in another subforum?
> Like Network/Internet or Programming/Scripting ones… Or would I be
> warned for double post?

No, cron and mail are fine here. The problem is centos, we know nothing
of centos, can not help. Not that we don’t want to. Unless somebody
comes along who does know.

The mails I talk about are internal to the machine, they are not sent
over the network.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)