Find the answer to your Linux question:
Results 1 to 7 of 7
Hi everyone, I am new to Linux and know nothing about it. I am currently working on my bachleors degree in network and communications management through Devry University Online. One ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    3

    college student needs help with bash script


    Hi everyone,

    I am new to Linux and know nothing about it. I am currently working on my bachleors degree in network and communications management through Devry University Online. One of my classes this session is Netw240-Linux. I have to do a project proposal for this class and it is due by the end of next week. I have already found a script that I want to use for this paper. My problem is that I can not find anything that explains what each line of the script does. For this paper I have to take each line of the script and explain what it does and the purpose for it. I have googled and searched the linux website and I still can't find anything that explains script lines to me. I am not asking anyone to give me the answers, I just want to be pointed in the right direction so that I can find the answers on my own. I am at my wits end and didn't know where else to turn to to get help. Below is a copy of the script that I will be using for this paper. Thank you to anyone that can help me. Well, apparently it won't let me add the script to this thread. The script I want to use is to backup configuration files from mulitple servers using scp and I got it from the zazzybob website.

  2. #2
    Just Joined!
    Join Date
    Dec 2006
    Posts
    85
    you have to wrap your code in code blocks (CODE inside of []'s)
    but i cant help you without knowing what you are talking about

  3. #3
    Just Joined!
    Join Date
    May 2009
    Posts
    3
    What I have to do is explain each line of the script like this:

    #!/bin/bash
    This statement is required as the first interpreted line in a shell script. It is used to inform the kernel on which shell to use when interpreting the script. The # is normally treated as a comment line. When it is followed by the !, the shell interprets the remainder of the string as the interpreter specification (Das, 2001, p.539).

    Below is the script that I have chosen to use for this paper. As I said, I don't want anyone telling me what the answers are, I just need to be pointed in the right direction. Thank you for helping me.


    BZIP2="/bin/bzip2"
    DATE="/usr/bin/date"
    ECHO="/usr/bin/echo"
    SCP="/usr/bin/scp"

    USER="root"
    SERVERS="server1 server2"

    SRC_DIR="/etc"
    SRC_FILES=( "${SRC_DIR}/foo.conf" "${SRC_DIR}/bar.conf" \
    "${SRC_DIR}/baz.conf" "${SRC_DIR}/baz_local.conf" )

    TIMESTAMP=$( ${DATE} +"%Y%m%d-%H%M" )

    for SERVER in ${SERVERS}; do
    ${ECHO} "Backing up configuration from [${SERVER}]"
    DEST_DIR="/home/user/config/${SERVER}"
    for SRC_FILE in ${SRC_FILES[@]}; do
    DEST_FILE="${DEST_DIR}/${SRC_FILE##*/}-${TIMESTAMP}"
    ${SCP} ${USER}@${SERVER}:${SRC_FILE} ${DEST_FILE}
    ${BZIP2} -9 ${DEST_FILE}
    done
    done

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Dec 2006
    Posts
    85
    hmm pointing to the right dirrection:
    man bash

    and man -k <search string>
    probably the best way to point you in the right dirrection without telling you what each line does

    also you can often break down the lines in command line, for instance a few seconds ago i wasnt quite sure what it was doing with date, so i did this:
    DATE="/bin/date"; TIMESTAMP=$( ${DATE} +"%Y%m%d-%H%M" ); echo $TIMESTAMP
    (i changed it since date is in /bin for me...)
    then i just ran date by itself, then again with +%Y%m%d-%H%M, then i removed the timestamp declaration and replaced it with echo (so it was echo $(...) ) then i removed the outter bracket and echoed that. this told me what that part of the bash was doing. you can do this with pretty much any line.

    hope that helps

  6. #5
    Just Joined!
    Join Date
    May 2009
    Location
    Oregon
    Posts
    51
    Bash is a very limited program, it mostly calls other programs to do its work.
    At the command prompt in Linux, type:
    man bash
    (or Google man bash)

    That will give you a complete description of how the shell works, and what individual commands do. the q button quits the manual.

    In a shell script everything after # is a comment.
    # This is a comment.
    sleep 10 # this is a command to sleep 10 seconds, followed by a comment.
    # Unfortunately, your script has no comments.....!!

    # try typing:
    man bzip # at a BASH prompt in Linux.
    # to learn about the bzip utility.

    # You need to know about variables....
    # A variable is something simple; a name followed by an = sign.
    MYVARIABLENAME="sleep 10" # This is a variable assigned a value.

    # To retrieve the contents of the variable, (print it), just do:
    echo $MYVARIABLENAME

    # to actually DO (execute a command held in the variable)
    # type:
    $MYVARIABLENAME

    #That will cause (in the example I gave) the computer to sleep for 10 seconds.
    #you can use man to find out about all kinds of things...

    # Cheers.

  7. #6
    Just Joined!
    Join Date
    May 2009
    Posts
    3
    Thank you everyone so much. I currently don't have Linux installed on my system, but I think a friend of mine does so I will use their computer this weekend. I tried using virtual box so that I could put Linux on my computer but of course I don't know anything about it either so I am having trouble getting it to work. But I am not giving up, I will figure it out. Again, Thank you both for the information.

  8. #7
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    Besides man bash look at info bash as well. You don't need to install linux in a virtual machine or otherwise - you can run a live CD or live USB (if your machine supports booting from a USB flash drive.) I would recommend something relatively small and quick to load like Puppy Linux or Slitaz. You can use unetbootin to easily create a live USB.

    Or you can install Ubuntu inside Windows with WUBI.

    The BASH manual.

    More bash scripting guides:
    All about Linux: 10 Seconds Guide to Bash Shell Scripting

    Linux Shell Scripting Tutorial - A Beginner's handbook

    Advanced Bash-Scripting Guide

Posting Permissions

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