Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Problem with command cron in SUSE

  1. #1

    Default Problem with command cron in SUSE

    Hi everybody, i'm new at this community!
    I'm having a problem with the command cron in suse
    I'm also learning bash so here is the question.. i want to try this command, with a basic script:

    i want to use cron, for a date (example now: 17:10 PM on 17/6/2015, minute 7), that execute a "Hello World" and sabe it on another file

    I think is something like this, but is not working at all.

    On crontab file i put

    07 17 17 6 * echo 'hello' > /etc/logcron.txt
    07 17 17 6 * /root/user/pruebacron.txt (here pruebacron is a script that includes echo 'hello' > /etc/logcron.txt)
    07 17 17 6 * echo 'hello' | > /etc/logcron.txt (here i included pipe.. to send the answer to the file...)

    but neither of the alternatives worked fine.. maybe im confused with sintaxis... i hope u can help me

    thank you very much!
    licha!

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,485
    Blog Entries
    15

    Default Re: Problem with command cron in SUSE

    Hi
    By default cron has no environment set, in either cron or your scripts need the full path to the command.

    You can find this with the which command, or in your script use which..

    Code:
    crontab
    /usr/bin/echo "Hello from echo" > /tmp/mycronjob.txt"
    
    Script
    #!/bin/bash
    MYECHO=`/usr/bin/which echo`
    $MYECHO "A new Hello from echo" > /tmp/mycronjob.txt
    You can also set the paths environment variable in the crontab....

    You should also look at putting stuff into /tmp and use some other script or method to check it... if your task accidentally removes files, better in /tmp
    Last edited by malcolmlewis; 17-Jun-2015 at 13:46.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

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

    Default Re: Problem with command cron in SUSE

    On 2015-06-17 22:16, licha lop wrote:

    > On crontab file i put


    What crontab file exactly? There are many.


    Normally you would, as user, run "crontab -e", per the manual. If you
    don't like the default editor, change the EDITOR variable.

    There are also tools in kde to edit the user crontab, I don't remember
    the name.


    > 07 17 17 6 * echo 'hello' > /etc/logcron.txt


    Does the user that run this have permissions to write there?

    > 07 17 17 6 * /root/user/pruebacron.txt (here pruebacron is a script that
    > includes echo 'hello' > /etc/logcron.txt)


    Normally you don't name a script as .txt, although Linux does not care.
    It has to have executable permissions, though. And the directory you
    have used is also strange, although it does not matter, provided the job
    runs as root. Which makes me think that you are running as root, which
    is something you should never do.


    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)

  4. #4

    Default Re: Problem with command cron in SUSE

    Quote Originally Posted by malcolmlewis View Post
    Hi
    By default cron has no environment set, in either cron or your scripts need the full path to the command.

    You can find this with the which command, or in your script use which..

    Code:
    crontab
    /usr/bin/echo "Hello from echo" > /tmp/mycronjob.txt"
    
    Script
    #!/bin/bash
    MYECHO=`/usr/bin/which echo`
    $MYECHO "A new Hello from echo" > /tmp/mycronjob.txt
    You can also set the paths environment variable in the crontab....

    You should also look at putting stuff into /tmp and use some other script or method to check it... if your task accidentally removes files, better in /tmp
    Hey, thanks.
    But there, where do u set the time? On the crontab?
    The crontab i was talking about is the one wich is in /etc/crontab
    It would be:

    crontab
    Minute Hour ... ... ... /usr/bin/echo "Hello from echo" > /tmp/mycronjob.txt" ?
    Do i have to create before the mycronjob.txt? Or it creates automatically.
    The idea in this case would be to see on that txt lines saying "Hello from echo" all the time the job is executed? Correct?

    And if i want to crontab execute another script, would be with both commands?
    Script
    #!/bin/bash
    MYECHO=`/usr/bin/which echo`
    $MYECHO "A new Hello from echo" > /tmp/mycronjob.txt

    And the one that goes on the crontab file? (without the > /tmp/mycronjob.txt because im doing that on my script)
    XX XX XX XX XX /usr/bin/echo scriptBefore

    Thanks.. i hope i understood.. jaja

  5. #5

    Default Re: Problem with command cron in SUSE

    Quote Originally Posted by robin_listas View Post
    On 2015-06-17 22:16, licha lop wrote:


    Normally you would, as user, run "crontab -e", per the manual. If you
    don't like the default editor, change the EDITOR variable.

    There are also tools in kde to edit the user crontab, I don't remember
    the name.


    Normally you don't name a script as .txt, although Linux does not care.
    It has to have executable permissions, though. And the directory you
    have used is also strange, although it does not matter, provided the job
    runs as root. Which makes me think that you are running as root, which
    is something you should never do.

    the user have permissions.
    good to know about the txt.. don't know why i put that extension haha! but as you said, it doesn't affect.
    thanks!

  6. #6
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,485
    Blog Entries
    15

    Default Re: Problem with command cron in SUSE

    On Wed 17 Jun 2015 11:46:01 PM CDT, licha lop wrote:


    malcolmlewis;2715657 Wrote:
    > Hi
    > By default cron has no environment set, in either cron or your scripts
    > need the full path to the command.
    >
    > You can find this with the which command, or in your script use
    > which..
    >
    > >

    Code:
    --------------------
    > >

    >
    > crontab
    > /usr/bin/echo "Hello from echo" > /tmp/mycronjob.txt"
    >
    > Script
    > #!/bin/bash
    > MYECHO=`/usr/bin/which echo`
    > $MYECHO "A new Hello from echo" > /tmp/mycronjob.txt
    >

    --------------------
    > >

    >
    > You can also set the paths environment variable in the crontab....
    >
    > You should also look at putting stuff into /tmp and use some other
    > script or method to check it... if your task accidentally removes
    > files, better in /tmp


    Hey, thanks.
    But there, where do u set the time? On the crontab?
    The crontab i was talking about is the one wich is in /etc/crontab
    It would be:

    crontab
    Minute Hour ... ... ... /usr/bin/echo "Hello from echo" >
    /tmp/mycronjob.txt" ?
    Do i have to create before the mycronjob.txt? Or it creates
    automatically.
    The idea in this case would be to see on that txt lines saying "Hello
    from echo" all the time the job is executed? Correct?

    And if i want to crontab execute another script, would be with both
    commands?
    Script
    #!/bin/bash
    MYECHO=`/usr/bin/which echo`
    $MYECHO "A new Hello from echo" > /tmp/mycronjob.txt

    And the one that goes on the crontab file? (without the >
    /tmp/mycronjob.txt because im doing that on my script)
    XX XX XX XX XX /usr/bin/echo scriptBefore

    Thanks.. i hope i understood.. jaja


    Hi
    For a user crobjob you don't do anything in /etc, just as the user run
    the command;
    Code:
    crontab -e
    Then you enter the time etc your wanting it to occur.

    To see what is present in the user crontab use;
    Code:
    crontab -l
    You can have one script that will do everything, lots of little scripts
    doing different things. It all depends on what your wanting to do....

    For system jobs, you just place the executable
    script in cron.daily .hourly .weekly and .monthly.

    You can also use systemd timers if wanting jobs to occur at less than 1
    minute.

    Perhaps detailing exactly what your wanting to do and timing etc might
    be better so users can offer advice....

    --
    Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
    SUSE Linux Enterprise Desktop 12 GNOME 3.10.1 Kernel
    3.12.43-52.6-default If you find this post helpful and are logged into
    the web interface, please show your appreciation and click on the star
    below... Thanks!


  7. #7

    Default Re: Problem with command cron in SUSEbt29cg

    Quote Originally Posted by malcolmlewis View Post
    Hi
    For a user crobjob you don't do anything in /etc, just as the user run
    the command;
    Code:
    crontab -e
    Then you enter the time etc your wanting it to occur.

    To see what is present in the user crontab use;
    Code:
    crontab -l
    You can have one script that will do everything, lots of little scripts
    doing different things. It all depends on what your wanting to do....

    For system jobs, you just place the executable
    script in cron.daily .hourly .weekly and .monthly.

    You can also use systemd timers if wanting jobs to occur at less than 1
    minute.

    Perhaps detailing exactly what your wanting to do and timing etc might
    be better so users can offer advice....

    --
    Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
    SUSE Linux Enterprise Desktop 12 GNOME 3.10.1 Kernel
    3.12.43-52.6-default If you find this post helpful and are logged into
    the web interface, please show your appreciation and click on the star
    below... Thanks!
    Hey, thank u very much! Tomorrow i'll try what u have told me.
    But basically i want that every day at 17:00PM, a file (script) located in another folder (ej: /home/myfolder/script), and also HAVE a log that this task WAS executed (this log could be located on that direction un tmp).

    Now im trying it with something easier: a script that only says "Hello World". Cron that script, and log it. That would me the task.

    Thanks

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

    Default Re: Problem with command cron in SUSE

    On 2015-06-18 06:06, licha lop wrote:

    > Hey, thank u very much! Tomorrow i'll try what u have told me.
    > But basically i want that every day at 17:00PM, a file (script) located
    > in another folder (ej: /home/myfolder/script), and also HAVE a log that
    > this task WAS executed (this log could be located on that direction un
    > tmp).


    Just start by running "crontab -e" as the user that you want the cron
    job to run, and type the sequence...


    Code:
    33 22 * * *   /home/cer/bin/darlavara >> /home/cer/bin/darlavara.log

    It is that simple.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)
    Last edited by hcvv; 18-Jun-2015 at 05:19. Reason: repaired CODE tag

  9. #9

    Default Re: Problem with command cron in SUSE

    Hi,

    Just a heads up, the default editor in openSUSE is vim, so unless you know how to use vim you don't have to worry about a thing when editing that crontab file.
    That being said you can change the default editor (temporary)

    Code:
    EDITOR=foo; export EDITOR
    Code:
    crontab -e
    Of course you need to change foo into the file editor you know

    A permanent change would be editing

    Code:
    ~/.profile
    for a single user

    or

    Code:
    /etc/profile.local
    for system wide changes.

    Note I don't use ze C shell nor its variants since some folks say it does not honor *.profile but that is another story
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  10. #10

    Default Re: Problem with command cron in SUSE

    Well, i'am here again.
    It worked. This is what i did

    Script
    Code:
    #!/bin/bash
    echo 'Hello World'
    echo 'Save It' >> /root/user/log.txt
    In crontab -e
    Code:
    22 10 18 6 * /root/user/script.sh
    Now, what only remains, is to open my browser (mozzilla in this case) from my crontab
    In my crontab -e, at the end i have put
    Code:
    localhost/script_exec.php?data_sources=20
    But the browser doesn't appear at that time. I think it's doing nothing.
    Maybe to opening a php page, i have to put another command that i don't know.. so may be you can help me with that too!

    Thanks to all!!!

Page 1 of 3 123 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
  •