Setting cron job using vi - Mandriva

This is a discussion on Setting cron job using vi - Mandriva ; Over the last few days I've read quite a bit on this and other groups about 'cron' jobs so to learn a bit more about cron decided to set one for myself. Following the instructions, the first line I type ...

+ Reply to Thread
Results 1 to 18 of 18

Thread: Setting cron job using vi

  1. Setting cron job using vi

    Over the last few days I've read quite a bit on this and other groups
    about 'cron' jobs so to learn a bit more about cron decided to set one for
    myself.

    Following the instructions, the first line I type into console is 'vi
    /etc/cron.daily/auto-update' and this creates a format within the console
    I must assume is 'vi'. The first line I attempt to type into this is
    '#!/bin/bash' but when I do this the first two characters (#!) don't
    appear anywhere although the rest of the line appears at the bottom line
    of the console.

    I don't want to **** anything up here, so what am I doing wrong? Is there
    another way I can do this to avoid using 'vi'? Like creating a text file
    with the correct commands and saving it as an executable somewhere?

    A lot of the information I glean using Google sort of presupposes a level
    of knowledge of some things that I have not yet attained, some of which I
    know some of this group's users will find second nature.

    Nothing I have learned in my life has made me feel as stupid as Linux
    makes me feel sometimes, but I fully intend to come out on top in this
    particular competition. Eventually :-)

    --
    Registered Linux User 413057.
    Both Mandriva 2007 and Ubuntu 6.06
    You can have it all. My empire of hurt.

  2. Re: Setting cron job using vi

    Aardvark writes:

    > Over the last few days I've read quite a bit on this and other groups
    > about 'cron' jobs so to learn a bit more about cron decided to set one for
    > myself.
    >
    > Following the instructions, the first line I type into console is 'vi
    > /etc/cron.daily/auto-update' and this creates a format within the console


    What instructions did you find that said to edit a file there.
    I suspect they are bad instructions.

    > I must assume is 'vi'. The first line I attempt to type into this is
    > '#!/bin/bash' but when I do this the first two characters (#!) don't
    > appear anywhere although the rest of the line appears at the bottom line
    > of the console.


    Crontab files don't start with #!/bin/bash.
    Maybe you need to read some more.

    > I don't want to **** anything up here, so what am I doing wrong? Is there
    > another way I can do this to avoid using 'vi'? Like creating a text file
    > with the correct commands and saving it as an executable somewhere?
    >
    > A lot of the information I glean using Google sort of presupposes a level
    > of knowledge of some things that I have not yet attained, some of which I
    > know some of this group's users will find second nature.
    >
    > Nothing I have learned in my life has made me feel as stupid as Linux
    > makes me feel sometimes, but I fully intend to come out on top in this
    > particular competition. Eventually :-)


    If you don't want to learn the "odd" command syntax of vi,
    use nedit instead.

  3. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 15:37:18 GMT, Aardvark wrote:
    >
    > I don't want to **** anything up here, so what am I doing wrong? Is there
    > another way I can do this to avoid using 'vi'? Like creating a text file
    > with the correct commands and saving it as an executable somewhere?


    That is what a cron job is. Just a text script executed via cron.

    Create the script, test/debug it, then tell cron about it.

    If you were to do a
    cat /etc/crontab
    you would see the system cron job entries. Looking at a snippet from
    my install we see
    01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
    02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily

    first line says to have nice execute run-parts 1 minute after the hour with a
    lowered priority. run-parts is to execute each script in /etc/cron.hourly.

    Second line has run-parts executing scripts in /etc/cron.daily
    2 minutes after 4am.


  4. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:

    > Aardvark writes:
    >
    >
    > What instructions did you find that said to edit a file there.
    > I suspect they are bad instructions.
    >


    The softpedia ones here:
    http://66.102.9.104/search?q=cache:8...lnk&cd=3&gl=uk

    >
    > Crontab files don't start with #!/bin/bash.
    > Maybe you need to read some more.
    >


    The instructions give a few lines of code to copy/paste. The first line is
    '#!/bin/bash'.

    >
    > If you don't want to learn the "odd" command syntax of vi, use nedit
    > instead.


    I want to learn anything that is effective in making the OS do anything I
    want the OS to do.

    --
    Registered Linux User 413057.
    Both Mandriva 2007 and Ubuntu 6.06
    You can have it all. My empire of hurt.

  5. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 16:34:31 +0000, Bit Twister wrote:

    >
    > That is what a cron job is. Just a text script executed via cron.
    >


    Makes me wonder why the instructions I was using says to use 'vi'

    > Create the script, test/debug it, then tell cron about it.
    >


    Is the wording of the script correct as shown at
    http://66.102.9.104/search?q=cache:8...lnk&cd=3&gl=uk

    As for test/debug, google is my friend. Ditto for telling cron :-)

    > If you were to do a
    > cat /etc/crontab
    > you would see the system cron job entries. Looking at a snippet from
    > my install we see
    > 01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
    > 02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily
    >


    Yes, I've got the same plus another two lines regarding weekly and monthly.



    --
    Registered Linux User 413057.
    Both Mandriva 2007 and Ubuntu 6.06
    You can have it all. My empire of hurt.

  6. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 16:52:01 GMT, Aardvark wrote:
    > On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:
    >> If you don't want to learn the "odd" command syntax of vi, use nedit
    >> instead.

    >
    > I want to learn anything that is effective in making the OS do anything I
    > want the OS to do.


    You get to pick the application/tool/program to use for a given task.
    Your knowledge about the tool/app is what is going to make it
    "effective" for your use.

    First thing is to try the man and info documentation for every
    app/tool you start to use.

    Next I suggest doing something like
    locate -i app_name_here | grep -i doc
    and cut/paste result into your browser.

    Example:
    locate -i vi | grep -i doc

    Too many hits, try
    locate -i /vi | grep -i /doc/

    In your case, vim is a more user friendly vi like application.

    Sometimes I try for a index. Using your example

    locate -i /vi | grep -i /doc/ | grep -i index
    which might return something of interest like
    /usr/share/doc/vim-common-7.0/doc/index.txt

    Just cut/paste into your browser. I find it handy to just enter the directory
    /usr/share/doc/vim-common-7.0/doc
    and browse from there if there is no index.htm* file.


  7. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:

    > Aardvark writes:
    >> Following the instructions, the first line I type into console is 'vi
    >> /etc/cron.daily/auto-update' and this creates a format within the console

    >
    > What instructions did you find that said to edit a file there.
    > I suspect they are bad instructions.
    >

    Why ?
    >
    >> I must assume is 'vi'. The first line I attempt to type into this is
    >> '#!/bin/bash' but when I do this the first two characters (#!) don't
    >> appear anywhere although the rest of the line appears at the bottom line
    >> of the console.

    >
    > Crontab files don't start with #!/bin/bash.
    > Maybe you need to read some more.
    >


    He is not talking about a crontabfile, but about a script, placed in
    /etc/cron.daily
    So it will start with #!/bin/bash


    --
    Panic, chaos & disorder, my work here is done
    http://beginnerslinux.org

  8. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 17:07:31 GMT, Aardvark wrote:
    >
    > Makes me wonder why the instructions I was using says to use 'vi'


    Because vi is a text editor found on most all the linux/unix OSs.
    I like tools which do syntax highlighting. emacs, nedit, kwrite....

    Hey, use
    kwrite your_script_here


    > Is the wording of the script correct as shown at
    > http://66.102.9.104/search?q=cache:8...lnk&cd=3&gl=uk


    Define correct. I would say it isn't.

    I feel a person should code/test/debug in their own account.

    Once it works then the script is install into the production
    environment and tested. In a perfect world, you would test in a
    pre-production machine before copying code into production.

    To make it more correct, in my eyes, you create/edit/test/debug and then
    cp script /etc/cron.daily

    As for what is going on in the script, I found the media update can
    fail for one or more /media/ lines found in /etc/urpmi/urpmi.cfg and
    that is not what I want to go un-noticed.

    My script verifies the mirror is up. Then I check the status of each media
    update, then run the software update and check it's results.

    Your average hacker creates the script with the commands and gets it
    to run and maybe goes back and add checks.

    Your average coder/programmer adds checks after each command so the
    script tells you when it has problems. Makes it easier to debug.

    Status checks can be made against the return code found in #?
    Other checks may have to be found in output/log files using another
    tool like grep.

    For extra points, read
    http://tldp.org/LDP/abs/html/index.html

  9. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 17:50:04 +0000, Bit Twister wrote:

    >
    > For extra points, read
    > http://tldp.org/LDP/abs/html/index.html


    Jeebus! You've got me on ADVANCED bash scripting?
    All I know about bash is that it's a word I've come across on a number of
    occasions since I've been using Linux (two months now).

    I'm going now. Going to read up on advanced bash-scripting.

    I may be quite some time. :-)

    --
    Registered Linux User 413057.
    Both Mandriva 2007 and Ubuntu 6.06
    You can have it all. My empire of hurt.

  10. Re: Setting cron job using vi

    Aardvark writes:

    > On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:
    >
    >> Aardvark writes:
    >> If you don't want to learn the "odd" command syntax of vi, use nedit
    >> instead.

    >
    > I want to learn anything that is effective in making the OS do anything I
    > want the OS to do.


    Well, vi is a very effective editor, especially if you are a UNIX admin
    or programmer, but it's a big subject, possibly as big as bash scripting
    and much bigger than your subject line subject.

    No harm in using one of the more intuitive editors like nedit.

  11. Re: Setting cron job using vi

    repo writes:

    R> On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:
    >
    >> Aardvark writes:
    >>> Following the instructions, the first line I type into console is 'vi
    >>> /etc/cron.daily/auto-update' and this creates a format within the console

    >>
    >> What instructions did you find that said to edit a file there.
    >> I suspect they are bad instructions.
    >>

    > Why ?


    Well because I looked at the subject line and thought the OP
    was trying to create a crontab file.

    Turns out the OP is creating a script.

    As a regular user, I still wouldn't put scripts there.
    And any learning should be done as a regular user,
    not root.

  12. Re: Setting cron job using vi

    On 2007-04-05, Aardvark wrote:
    > On Thu, 05 Apr 2007 17:50:04 +0000, Bit Twister wrote:
    >
    >>
    >> For extra points, read
    >> http://tldp.org/LDP/abs/html/index.html

    >
    > Jeebus! You've got me on ADVANCED bash scripting?
    > All I know about bash is that it's a word I've come across on a number of
    > occasions since I've been using Linux (two months now).
    >
    > I'm going now. Going to read up on advanced bash-scripting.
    >
    > I may be quite some time. :-)


    I've been using Linux for a few years now, and I know next to nothing
    about bash scripts.

    My approach is to work out how to do something, when I have something that
    I want to do. The incentive makes it more likely that I'll persevere.

    For managing cron jobs, I use the GUI provided by a program called webmin,
    which runs in your web browser.

    My favourite file manager is mc, which has a very 'intuitive' text
    processor of its own which can also be run directly as mcedit; I'm using
    it now to write this article. Vi and Vim (and emacs and xemacs) baffled
    me too much. Vi is worth learning the basics for, because it's almost
    certain to be installed on any Linux or Unix system and a few admin tools
    (eg visudo) are built on it.

    --
    -- ^^^^^^^^^^
    -- Whiskers
    -- ~~~~~~~~~~

  13. Re: Setting cron job using vi

    Aardvark writes:

    >Over the last few days I've read quite a bit on this and other groups
    >about 'cron' jobs so to learn a bit more about cron decided to set one for
    >myself.


    >Following the instructions, the first line I type into console is 'vi
    >/etc/cron.daily/auto-update' and this creates a format within the console
    >I must assume is 'vi'. The first line I attempt to type into this is
    >'#!/bin/bash' but when I do this the first two characters (#!) don't
    >appear anywhere although the rest of the line appears at the bottom line
    >of the console.


    OK, first you want to set up your own cron file. /etc/cron* files are all
    root cron files-- ie run by root.
    vi is an editor, so running
    vi /etc/cron.daily/auto-update
    is you editing that latter file.
    So you need to learn how to use vi. vi has two modes-- a command mode and
    an isert mode. YOu start in the command mode. All chachters you type in are
    assumed to be commands. However there is no command starting with #, and !
    is the command to start trying to run a shell command.
    To type into the file, you first give the command i.
    Then you are in insert mode. Now whereever the cursor is, letters will be
    inserted into the file.
    to get back to command mode hit the escape key (upper left of the keyboard)
    To quit without writing the file,
    get into command mode and then type
    :q!
    To write out the file type
    :w
    To write and quit
    :wq

    A few other commands:
    to erase the character under the curson, type x in command mode. To erase a
    line type dd in command mode.

    These (plus the cursor keys ) will get you started.



    >I don't want to **** anything up here, so what am I doing wrong? Is there
    >another way I can do this to avoid using 'vi'? Like creating a text file
    >with the correct commands and saving it as an executable somewhere?


    You can use any editor you wish. Just make sure you save the file as a text
    file.


    >A lot of the information I glean using Google sort of presupposes a level
    >of knowledge of some things that I have not yet attained, some of which I
    >know some of this group's users will find second nature.


    >Nothing I have learned in my life has made me feel as stupid as Linux
    >makes me feel sometimes, but I fully intend to come out on top in this
    >particular competition. Eventually :-)


    Not stupid, unknowledgeable. To not know something is not stupidity. To
    refuse to know something may be.




  14. Re: Setting cron job using vi

    Dan Espen writes:

    >Aardvark writes:


    >> Over the last few days I've read quite a bit on this and other groups
    >> about 'cron' jobs so to learn a bit more about cron decided to set one for
    >> myself.
    >>
    >> Following the instructions, the first line I type into console is 'vi
    >> /etc/cron.daily/auto-update' and this creates a format within the console


    >What instructions did you find that said to edit a file there.
    >I suspect they are bad instructions.


    >> I must assume is 'vi'. The first line I attempt to type into this is
    >> '#!/bin/bash' but when I do this the first two characters (#!) don't
    >> appear anywhere although the rest of the line appears at the bottom line
    >> of the console.


    >Crontab files don't start with #!/bin/bash.
    >Maybe you need to read some more.


    The files in /etc/cron.daily/ are NOT crontab files. They are executables,
    and do start with
    #!/bin/bash

    It would be good if you read his post before commenting.


    >> I don't want to **** anything up here, so what am I doing wrong? Is there
    >> another way I can do this to avoid using 'vi'? Like creating a text file
    >> with the correct commands and saving it as an executable somewhere?
    >>
    >> A lot of the information I glean using Google sort of presupposes a level
    >> of knowledge of some things that I have not yet attained, some of which I
    >> know some of this group's users will find second nature.
    >>
    >> Nothing I have learned in my life has made me feel as stupid as Linux
    >> makes me feel sometimes, but I fully intend to come out on top in this
    >> particular competition. Eventually :-)


    >If you don't want to learn the "odd" command syntax of vi,
    >use nedit instead.


    There are lots of editors, all of which need to be learned. nedit, jedit,
    jed, pico, ... Or is you want to go over to the "other side" with an
    equally obscure command syntax, emacs.
    The advantage of both vi and emacs is that they available on all unix
    systems, and are useable in console text mode. Ie, they do not require a
    windowing system. This makes them very useful. Obscure however they both
    are.


  15. Re: Setting cron job using vi

    Aardvark writes:

    >On Thu, 05 Apr 2007 16:34:31 +0000, Bit Twister wrote:


    >>
    >> That is what a cron job is. Just a text script executed via cron.
    >>


    >Makes me wonder why the instructions I was using says to use 'vi'


    Because vi is an editor which is universally available and runnable under
    almost all situations.


    >> Create the script, test/debug it, then tell cron about it.
    >>


    >Is the wording of the script correct as shown at
    >http://66.102.9.104/search?q=cache:8...lnk&cd=3&gl=uk


    >As for test/debug, google is my friend. Ditto for telling cron :-)
    >
    >> If you were to do a
    >> cat /etc/crontab
    >> you would see the system cron job entries. Looking at a snippet from
    >> my install we see
    >> 01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
    >> 02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily
    >>


    >Yes, I've got the same plus another two lines regarding weekly and monthly.


    Those are cron files. They run script files in the various /etc/cron.*/
    directories.
    (that is what the command "run-parts" does-- run all of the files in the
    directory listed at the end.)





    >--
    >Registered Linux User 413057.
    >Both Mandriva 2007 and Ubuntu 6.06
    >You can have it all. My empire of hurt.


  16. Re: Setting cron job using vi

    Bit Twister writes:

    >On Thu, 05 Apr 2007 16:52:01 GMT, Aardvark wrote:
    >> On Thu, 05 Apr 2007 12:33:08 -0400, Dan Espen wrote:
    >>> If you don't want to learn the "odd" command syntax of vi, use nedit
    >>> instead.

    >>
    >> I want to learn anything that is effective in making the OS do anything I
    >> want the OS to do.


    >You get to pick the application/tool/program to use for a given task.
    >Your knowledge about the tool/app is what is going to make it
    >"effective" for your use.


    >First thing is to try the man and info documentation for every
    >app/tool you start to use.


    >Next I suggest doing something like
    > locate -i app_name_here | grep -i doc
    >and cut/paste result into your browser.


    >Example:
    >locate -i vi | grep -i doc


    >Too many hits, try
    >locate -i /vi | grep -i /doc/


    >In your case, vim is a more user friendly vi like application.


    On virtually every distro I know, vi IS just vim. It is soft link to vim.


    >Sometimes I try for a index. Using your example


    >locate -i /vi | grep -i /doc/ | grep -i index
    >which might return something of interest like
    >/usr/share/doc/vim-common-7.0/doc/index.txt


    >Just cut/paste into your browser. I find it handy to just enter the directory
    >/usr/share/doc/vim-common-7.0/doc
    >and browse from there if there is no index.htm* file.



  17. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 18:40:29 GMT, Unruh wrote:
    > Bit Twister writes:
    >
    >>In your case, vim is a more user friendly vi like application.

    >
    > On virtually every distro I know, vi IS just vim. It is soft link to vim.


    Yes, but the OP would be looking for vi not vim.

  18. Re: Setting cron job using vi

    On Thu, 05 Apr 2007 18:39:25 +0000, Unruh wrote:

    > Aardvark writes:
    >
    >>On Thu, 05 Apr 2007 16:34:31 +0000, Bit Twister wrote:

    >
    >>>
    >>> That is what a cron job is. Just a text script executed via cron.
    >>>

    >
    >>Makes me wonder why the instructions I was using says to use 'vi'

    >
    > Because vi is an editor which is universally available and runnable under
    > almost all situations.


    Exactly. vi is still there after all the rest have quit. It has a
    keystroke language all of it own and yet it works very well.




+ Reply to Thread