linix bash script

Discussion in 'Programmer's Corner' started by electronis whiz, Nov 20, 2011.

  1. electronis whiz

    Thread Starter Well-Known Member

    Jul 29, 2010
    i have to make a linix bash script for a class using our pdf book and somwhere on this sit it sounded like there was a test shell to try it saw nothing anywhere after liiking for aprox an hour. googled found somthin but think the flavor is wrong so my script wont work. can anyone take a look at this script for me. it looks like it should work. howeve if i can i would like to somhow get a total of every ramstick this command dosn't apear to do it. and a scripted calculator because there names of the valuse are the same i don't think will work. this script is suposed to work like a WMI filter use by windows domains.
    script is in atched notpad
    thanks for any help
    • lamo.txt
      File size:
      308 bytes
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    You aren't calling bash properly.

    First line should be:

    Not #/bin!/bash

    Try this script, expand on it.

    Code ( (Unknown Language)):
    1. #!/bin/bash
    2. freemem=`free | awk 'NR==2{print $4}'`
    3. totalmem=`free | awk 'NR==2{print $2}'`
    4. echo Hello, you have $freemem bytes of free RAM out of $totalmem available
    5. if [ $freemem -ge 256000 ]
    6. then
    7.         echo you have at least 256,000 bytes of free memory
    8. else
    9.         echo Only $freemem bytes of RAM are available, at least 256k is needed
    10. fi
    Remember to use the backtick ` to assign the output of a command to a variable in bash
    Last edited: Nov 20, 2011