LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-19-2009, 04:27 AM   #1
mele
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
Question Bash script server HDD monitoring


Hello freaks ,

I am new here and I am also new in programming bash. I have a question, maybe someone can help me...

So my problem is this: I have to write a bash script which should monitoring the HDD and when for e.g. the HDD is at 75% full, the script sends an email to the admin. The script should also create a cronjob... so here is the section of the script which sends errors:

Code:
if [script -x /usr/local/bin/]; then
   (scp script.sh root@SERVER:/usr/local/bin/);
fi
# Cronjob wird per SSH angelegt, es wird überprüft ob der Cronjob schon existiert, falls dies
# Fall ist, wird kein neuer Cronjob angelegt
if [crontab -x /etc/]; then
   (ssh root@SERVER 'echo "CRONJOB_ZEILE" >> /etc/cron; /etc/init.d/cron restart');
The following errors appears:
./script1: 6: [script: not found
./script1: 11: [crontab: not found

crontab is installed ...

any ideas??

greetings

mele
 
Old 05-19-2009, 07:03 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You need spaces between the test brackets and the string they contain. '[' is actually a bash built-in command (a synonym for 'test'), and without the space your script is trying to read the whole string as a command instead.

Code:
if [ script -x /usr/local/bin/ ]; then
Edit: what's the "script" here? It isn't part of a correct test construct.
Do you mean "[ -x /usr/local/bin/script.sh ]" instead? The test phrase should be simply "-x filename", so crontab doesn't belong in the second test there either.

As the ABSG says, the closing bracket is not actually strictly necessary, but modern versions of bash require it.

Last edited by David the H.; 05-19-2009 at 07:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a HTTP server using bash script sawaby Linux - Newbie 13 12-02-2011 11:28 AM
Port Monitoring bash script twantrd Programming 15 01-29-2009 12:59 AM
Bash script for monitoring changes in a directory tree librano Linux - Software 4 10-30-2008 07:36 PM
Bash script to test if I can SSH to a server? DanHulton Linux - General 2 05-18-2007 01:42 PM
bash script, monitoring running PID? thebover Programming 4 08-26-2004 02:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration