Find the answer to your Linux question:
Results 1 to 4 of 4
Hey peeps, I actually want to do this in Solaris, not Linux, but most commands appear to be the same, and I thought I was more likely to get help ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2004
    Location
    Various Europe...
    Posts
    22

    Tar script


    Hey peeps,

    I actually want to do this in Solaris, not Linux, but most commands appear to be the same, and I thought I was more likely to get help here than on the useless Solaris forums. My situation is that I'm trying to install a mail filter, and it keeps crashing. Each time it crashes, I have to pull a load of files off it in tar form for analysis, then restart it. Here is what I do :

    cd /var/opt/Sheriff
    tar -cf sheriff_logs_TODAYSDATE.tar *
    mv sheriff_logs_TODAYSDATE.tar /sheriff/bkp
    cd /opt/Sheriff
    tar -cf sheriff_config_TODAYSDATE.tar *
    mv sheriff_config_TODAYSDATE.tar /sheriff/bkp

    OK, I know this could technically be done in two commands, but this is the way I do it, its a bit easier to read this way! All I want is a simple script, so I can log in (I do this over SSH) and type, for example:

    ./make_tarfiles

    ...and make the tarfiles, and drop them into the /sheriff/bkp directory. In DOS I'd do this with a batch file, and I've been told you can do the same in Linux. Anybody want to tell me how?

    What I know (related) : how to use vi, how to use chmod

  2. #2
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,127
    Well if you have the details of what you have most of the script... you just need to put in a variable assignment for the date...

    A shell script and a batch file are really the same thing, just convention has the names split for the two OSes. To make a shell script you just need to add the magic bytcode to make it executable...
    Code:
    #!/bin/bash
    ...where you are using the bash shell. For basic commands like above you could just use 'sh' instead of bash. If you have the $DATE variable set you can simply replace the TODAYSDATE with it for it to work...

    Try something like this....
    Code:
    #!/bin/sh
    cd /var/opt/Sheriff
    tar -cf sheriff_logs_$DATE.tar *
    mv sheriff_logs_$DATE.tar /sheriff/bkp
    cd /opt/Sheriff
    tar -cf sheriff_config_$DATE.tar *
    mv sheriff_config_$DATE.tar /sheriff/bkp
    Actually you will either need to
    Code:
    chmod a+x yourscriptnamehere
    to make it executable to all by calling it's name or when you run it call it with sh
    Code:
    sh ./yourscriptnamehere
    Also if it is often used you may consider putting it somewhere in your PATH variable - i.e. copy to /usr/bin or if you have a ~/bin directory.

  3. #3
    Just Joined!
    Join Date
    Feb 2004
    Location
    Various Europe...
    Posts
    22
    Nice one!! Thanks mate, that "magic bytcode" was the part I was missing!

  4. #4
    Linux Enthusiast scientica's Avatar
    Join Date
    Sep 2003
    Location
    South- or "Mid-" Sweden
    Posts
    742
    Just my 2 coin-demnominators, the "magic bytes" in (shell) scripts are often refered to as the "shebang" (iirc per definition the first line in the file, and it must start with '#!' - if there's any thing/line before the shebang the magic is gone )

    I think it's better to remove the need for the mv and cd, since if it's across different mounts/paritions moving the files could be adding extra time. I haven't tried this yet but from what I make of ``man 1 tar'' this should work like a charm
    Code:
    #!/bin/sh
    tar -cf /sheriff/bkp/sheriff_logs_$DATE.tar /var/opt/Sherif
    tar -cf /sheriff/bkp/sheriff_config_$DATE.tar /opt/Sheriff
    oh, and if you want the file permissions to be kept I suggest you replace '-cf' with '-cpf', and if you want to have some compression - if it's raw text files then even a "light" compression should save much space and be fairly quick, just add 'z' (gzip) or '-j' (bzip2) to the arguments (just put them before the 'f' - or things might not work) and change '.tar' to reflect the compression, when decompressing just add 'z' or 'j' to the opts and tar will take care of it.
    Regards Scienitca (registered user #335819 - http://counter.li.org )
    --
    A master is nothing more than a student who knows something of which he can teach to other students.

Posting Permissions

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