Bash Script Help Needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script Help Needed
# 8  
Old 09-29-2016
More like this then. I think it's working too, this is weird. It also means that I initially over complicated the script.

Thank you.

Code:
FQDN=`/bin/domainname -f`
FILE=$FQDN.`date +%F`.txt
dir=/home/wviands
COUNT=`find $dir -type f -empty | wc -l`

find $dir -type f -empty > saved.txt 2>&1

if ! cmp -s saved.txt $FILE ; then

find $dir -type f -empty > $FILE

mail -s "HFS Test Has $COUNT Empty Files"  wviands@email < $FILE

fi

# 9  
Old 09-29-2016
You should not overwrite the "saved.txt" file in the first place, but use the last session's one for the comparison, then cp $FILE saved.txt.
# 10  
Old 09-29-2016
More like this:

Code:
find .... >$FILE
[[ -f saved.txt ]] || touch saved.txt
if ! cmp $FILE saved.txt
then
   [[ -s $FILE ]] && mail ... <$FILE
   cp $FILE saved.txt
fi


Last edited by rovf; 09-29-2016 at 10:54 AM.. Reason: fix bug
# 11  
Old 09-29-2016
The script I posted above is definitely working. I'm running it from cron every minute and tossing in or deleting random numbers of 0 byte files.

I tried...
Code:
find $dir -type f -empty > $FILE 2>&1
[[ -f saved.txt ]] || touch saved.txt
if ! cmp -s saved.txt $FILE ; then
mail -s "HFS Test Has $COUNT Empty Files"  wviands@email < $FILE
fi

...but it didn't seem to work, which means I didn't do it right. I don't write scripts but I know I need to learn. What is it that I did wrong? I'm probably not 'reading' what the script is doing correctly. Most likely I think it's doing one thing but it's really doing something else entirely.

I appreciate your taking the time to show me better ways of doing things.
# 12  
Old 09-29-2016
PLEASE provide more info: WHAT "didn't seem to work"? Post the contents of the files, the values of the variables, the result of the cmp command, mayhap a log of the script's execution.
# 13  
Old 09-29-2016
Quote:
Originally Posted by wviands
The script I posted above is definitely working. I'm running it from cron every minute and tossing in or deleting random numbers of 0 byte files.

I tried...
Code:
find $dir -type f -empty > $FILE 2>&1
[[ -f saved.txt ]] || touch saved.txt
if ! cmp -s saved.txt $FILE ; then
mail -s "HFS Test Has $COUNT Empty Files"  wviands@email < $FILE
fi

...but it didn't seem to work, which means I didn't do it right. I don't write scripts but I know I need to learn. What is it that I did wrong? I'm probably not 'reading' what the script is doing correctly. Most likely I think it's doing one thing but it's really doing something else entirely.

I appreciate your taking the time to show me better ways of doing things.
The part inside the then clause in your script is different from what I've posted. That's why it doesn't work.
This User Gave Thanks to rovf For This Post:
# 14  
Old 09-29-2016
Quote:
Originally Posted by rovf
The part inside the then clause in your script is different from what I've posted. That's why it doesn't work.
Basically, I made a complete mess of your script. Good grief, even my reading skills have gone downhill. My apologies, it's working fine now that I put in what you posted instead of what I thought I saw.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Question related to bash. Your help needed.

Dear Team, i have one question related to automation of adding new users based on txt file. Here we go: I have data.txt file which shows: bang dang benc One by one, after pressing enter. And now, I need scirpt which will add those users with home directory hidden within the file... (7 Replies)
Discussion started by: protos27
7 Replies

3. Shell Programming and Scripting

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

4. Shell Programming and Scripting

Help needed on ssh in bash scripting

HI I have the following requirement I have a script a.sh which will deploy files in multiple servers .The argument for the a.sh is abc.gz host1.conf where abc.gz is a zip file and one.conf will contain all the database connection string . Now I have to write a b.sh which will... (7 Replies)
Discussion started by: harry00514
7 Replies

5. Homework & Coursework Questions

Linux/UNIX Bash Shell Script trouble help needed!!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 2. Shell Bash Script 3. !/bin/bash if echo no directory then mkdir -p /home/AC_Drywall elif ; then echo "$dir already exist" fi (4 Replies)
Discussion started by: TomFord1
4 Replies

6. Shell Programming and Scripting

bash if statement help needed

Hi I need a script with an if statement that goes. I need it to search through all files within a directory with the extension .test if it finds the string '71502FSC1206' then do sed 's/71502FSC1206/\n&/g' > send.test If it finds the string '715MCH' or '715JAC' then I need it to move the... (1 Reply)
Discussion started by: firefox2k2
1 Replies

7. Shell Programming and Scripting

Help needed with bash script providing battery status

I'm really new to even doing a bash "hello world" script, so maybe someone would know how to do the following task, using bash scripting Need to login using ssh from one dell server into another dell server, and obtain the raid battery status, using dell's open manage software commands; then... (5 Replies)
Discussion started by: AJ-102111
5 Replies

8. UNIX Desktop Questions & Answers

Help needed tracing source of bash error

Issue resolved: The 'culprit file' was .bash_aliases. It had the naughty  (ASCII for the octal string Bash was detecting and returning an error about). I cleaned it up in Pico (see my post to the thread on favorite editors if you want background on why I use Pico/Nano), re-sourced it via... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

9. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

10. Shell Programming and Scripting

debugging in bash!!! help needed

Hi all, Am using bash shell. Am newbie, trying to understand the debugin process of a shell script... I am unable to comprehend the control flow ,meaning from where exactly the execution of the script begins... I tried using bash-xv <scriptname> but since am new ,am finding it difficult to... (2 Replies)
Discussion started by: wrapster
2 Replies
Login or Register to Ask a Question