5 Shell Scripts for Linux Newbies to Learn Shell Programming – Part II

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

Avishek Kumar

I am a major in computer science, love to research nix. I love to write codes and scripts, review distros, experiment Foss Technologies, write technical articles, Hack, of course Ethically. I am working as System Administrator (nix) for a NGO.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

You may also like...

63 Responses

  1. cagcak says:

    Here is my Decription script:
    ——————————————–
    #!/bin/bash
    echo “Enter Encrypted File Name:”
    read file;
    gpg -d $file”.gpg” > $file
    rm -rf $file”.gpg”
    ——————————————–
    So, by an eof error I’ve lost contens of the encrypted file, ‘pattern.sh.gpg’, and now I’ve got only ‘pattern.sh’ with 0 byte. What did I miss?

  2. Hunter says:

    Hello,

    this is how i wrote the decrypt script don’t know if thats the correct way though but it worked , the thing is that i couldn’t make the script to make the file to appear in its former name (the filename was hello.txt) so i give the option to make a newfilename.txt.

    Any help or advice is welcomed.
    Thanks for the tutorials it really helps.

    decrypt.sh script follows bellow
    #!/bin/bash
    echo “Welcome, I am ready to decrypt a file/folder for you”
    echo “currently I have a limitation, Place me to the same folder, where the file to be
    decrypted is present”
    echo “Enter the Exact File Name with extension”
    read file;
    gpg -d $file>hunter.txt
    echo “I have decrypted the file succesfully…”
    echo “Now I will be removing the encrypted file”
    rm -rf $file

  3. ViviG says:

    How can I show in Linux when -d parameter is supplied the three user in the system that uses more disk space in their homes. Sort these three user by the disk usage and for each of them show their name, total space and home directory.

    Output should be like this:

    Disk usage:
    Jane 204816/users/Jane
    Joe 102420/home/joe
    sync 12584 /sbin

  4. Pratik says:

    Hi Avishek,

    I am using Fedora 20 – Heisenberg. I wrote a script but the nested for loop is not working as intended. for the following variables I want to print:
    5 1 8 250 0 5180
    5 1 8 150 1 5181
    5 1 8 110 2 5182
    5 1 8 50 3 5183
    5 1 8 20 4 5184
    5 1 16 250 0 51165
    5 1 16 150 1 51166
    and so on…

    I keep getting the result:
    5 1 0 8 250 0 5180
    10 1 0 8 250 1 10181
    15 1 0 8 250 2 15182
    20 1 0 8 250 3 20183
    50 1 0 8 250 4 50184
    Can you tell me why the nested loop is not working? I would really appreciate your help.

    #!/bin/bash

    dist=(‘5′ ’10’ ’15’ ’20’ ’50’) #loop “i”
    retx=(‘1′ ‘3’ ‘5’) #loop “j”
    CWmin=0
    CWmax=(‘8′ ’16’ ’32’) #loop “k”
    numnodes=(‘250′ ‘150’ ‘110’ ’50’ ’20’) #loop “l”
    seed=0
    #seed=(‘0′)

    for(( i = 0; i < 5; i++ ))
    do
    for(( j = 0; i < 3; i++ ))
    do
    for(( k = 0; i < 3; i++ ))
    do
    for(( l = 0; i < 5; i++ ))
    do
    echo "$seed"
    echo ${dist[$i]} ${retx[$j]} $CWmin ${CWmax[$k]} ${numnodes[$l]} $seed ${dist[$i]}${retx[$j]}${CWmax[$k]}$seed
    ((seed=seed+1))
    done
    done
    done
    done

  5. Karthik says:

    Hi Avishek,

    I am a beginner. Would like to learn about shell scripting. What would you suggest to start of with?

  6. Hari om says:

    Thanks a lot sir for your Great help

  7. Kapur says:

    I need one help regarding creating new users script.

    • Avishek Kumar says:

      Let us know how we can help you?

      • Ram says:

        Hi Avishek Kumar,

        Please help me .
        I want run one jar file, that jar file and input.property file Application team provided and run that jar weekly once, Before running need to take mysql DB dump backup.

        Thanks,
        Ram

        • Avishek Kumar says:

          I didnt understand ur question.
          see if it helps

          Run Jar fie : java -jar filename.jar
          schedule the execution : you need to cron the job.

  8. Geoff says:

    thnx for this series … am looking forward to working through it … however have struck an issue with the script

    Script 1: Drawing a Special Pattern

    there appears to be a syntax error (near the ‘Second Stage comment’) that prevents it from running in entirety … which makes it a bit frustrating for noobs … :)

    any chance of having a look at it :)

    cheers

    Geoff

    • Dushyant says:

      @Geoff:- It’s just identation errors. Even I faced same problem. Just place that line onto new one with single for loop in one line and the problem will be solved. Cheers :)

      ~ Dushyant

  9. Keith says:

    I need some assistance with creating the Decrypt script, this is what I have so far.

    #!/bin/bash
    echo “Welcome, I am ready to decrypt a file/folder for you”
    echo “currently I have a limitation, Place me to thh same folder, where a file to be
    decrypted is present”
    echo “Enter the Exact File Name with extension”
    read file;
    gpg -d $file > $file.txt
    echo “I have decrypted the file successfully…”
    echo “Now I will be removing the encrypted file”

    It decrypts the file, but doesn’t ask for password, and adds the .gpg and .txt at the end of the file.

    My other questions were how to take the output of a script and put i into a file or folder.

    Please e-mail me at KJax50@yahoo.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Join Over 70000+ Linux Users
  1. 48590
  2. 2375
  3. 13200

Enter your email to get latest Linux Howto's