Need assistance with a simple script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need assistance with a simple script
# 1  
Old 02-07-2011
Need assistance with a simple script

I have a simple script. Do you know what I got this error?

./total_memory.ksh: line 5: [: missing `]'

Thanks
Code:
#! /bin/bash
setmem=30177660
totalMemory= grep MemTotal /proc/meminfo | awk '{print $2}'

if [$totalMemory -lt $setmem] ; then  
        echo "Total memory $totalMemory is less than :$setmem"
        exit 1

else
        echo "Total memory is :$totalMemory"
fi

Moderator's Comments:
Mod Comment Would you post "need assistance with my TV" in a forum about TV's? That would be pointless, because it's obvious, don't you think? Please use a descriptive subject title, and code tags!

Last edited by Scott; 02-07-2011 at 03:11 PM..
# 2  
Old 02-07-2011
Quote:
Originally Posted by Beginer0705
I have a simple script. Do you know what I got this error?

./total_memory.ksh: line 5: [: missing `]'

Thanks

====================

#! /bin/bash
setmem=30177660
totalMemory= grep MemTotal /proc/meminfo | awk '{print $2}'

if [$totalMemory -lt $setmem] ; then
echo "Total memory $totalMemory is less than :$setmem"
exit 1

else
echo "Total memory is :$totalMemory"
fi
I am not a bash expert,but if this was written in ksh I see a few problems.

It appears that the variable totalMemory is not set. You need to fix
that by doing somehting like this:
Code:
totalMemory=$(grep MemTotal /proc/meminfo | awk '{print $2}')

or
Code:
totalMemory=`grep MemTotal /proc/meminfo | awk '{print $2}'`

Next in the comparison put a space between the brackets and the
expression. Also qualify your vairables "$totalMemory" so if it's not set
your script will not bomb.

Last edited by Scott; 02-07-2011 at 03:15 PM..
# 3  
Old 02-07-2011
try:
Code:
if [ $totalMemory -lt $setmem ] ; then

"[" followed by a space
"]" before by a space

and also you might need follow up the BeefStu's suggestion when building a var.
This User Gave Thanks to yinyuemi For This Post:
# 4  
Old 02-07-2011
Thanks guys. It works perfectly!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need assistance in ksh script

requirement : I need to read a text file and find out which particular line has highest charcters on it using the shell script. I tried & was able to find out only for one line. I could not able to find out for the entire the line. sed -n '10 p' ctstest.sh | wc -w Please guide me... (5 Replies)
Discussion started by: ramkumar15
5 Replies

2. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

3. Shell Programming and Scripting

Dummy script assistance

Hi, I am new in ksh scripting and if anyone can help that would be great. I'm writing a script which will SSH to several machines and then would append a certain file from a NAS to the /etc/sudoers file the problem i am having is after the script connects to a certain server the commands are... (7 Replies)
Discussion started by: galuzan
7 Replies

4. Shell Programming and Scripting

Need assistance with simple shell script to organize files. [Code attached]

I need some help with this shell script for class. All it does is organize your files. It works, but in the log file, it needs to show the new filepaths of the moved files. Heres my log of my output: Starting to organize... movie2.wmv --> movie3.mov --> movie1.mpg --> song1.mp3 --> ... (3 Replies)
Discussion started by: ryandamartini
3 Replies

5. Shell Programming and Scripting

script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time. I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :. Now I'm... (2 Replies)
Discussion started by: em23
2 Replies

6. Shell Programming and Scripting

Shell Script Assistance

I am looking for a shell script or command to automate a process of opening many files in a directory and changing a string of text. Example: I have a apache web server that uses virtual hosting. There are approximately 2300 vhost entries or files. So in the directory... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

shell script assistance please

When I run this command (showstatus <username> <dbname>) in the prompt, the following will be displayed in the screen: 1. Show processes 2. Start process 3. Stop process 4. Go back to prompt Once i choose/type Option "1" (which is Show processes), it will display the list of processes... (5 Replies)
Discussion started by: xinoo
5 Replies

8. Shell Programming and Scripting

need assistance ----SH schell script

Hello All, I need to develop a script(SH]) to generate a comparison file between two files old and new file.The script takes in parameter the old file path and the new file path. And the script generates a file containing the comparison between the two files with this details: - Keys... (2 Replies)
Discussion started by: shahidbakshi
2 Replies

9. Shell Programming and Scripting

Need a little assistance with a shell script

I need to modify a script to send an attatched file. I have researched and read the faq's but have not found a solution for my script. Here is a copy of the code I am using: #!/bin/sh mysqldump --opt --skip-add-locks --user=****** --password=******* databasename | gzip >... (3 Replies)
Discussion started by: rickou812
3 Replies

10. Shell Programming and Scripting

KSH Script Assistance

Hey everyone, I'm newer than new when it comes to this ksh and scripting stuff, and unix in general. I have been thrown into a task at work that A: They expect me to come up to speed on, B: Show I can do this. (Program for the workgroup) Here's the script, part of it, from the overall... (3 Replies)
Discussion started by: Brusimm
3 Replies
Login or Register to Ask a Question