Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Using crontab...

  1. #1

    Default 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:
    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:
    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
    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.

  2. #2
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Using crontab...

    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. :-)

    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)

  3. #3

    Default Re: Using crontab...

    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:
    Code:
    cd /home/centosuser
    cp test1 test2
    scp suseuser@ipadress:/home/user/Documents/file1 /home/centosuser/file2
    Then I set my crontab task:
    Code:
    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Using crontab...

    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 :-)

    > 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 :-)

    Hint:

    Code:
    /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:

    Code:
    cer@Telcontar:~> which scp
    /usr/bin/scp
    cer@Telcontar:~>
    and then your cronjob would be:

    Code:
    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)

  5. #5

    Default Re: Using crontab...

    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:
    Code:
    /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!

  6. #6
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Using crontab...

    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)

  7. #7

    Default Re: Using crontab...

    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?

  8. #8

    Default Re: Using crontab...

    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...

  9. #9
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,654

    Default Re: Using crontab...

    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

  10. #10

    Default Re: Using crontab...

    @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...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •