First of all I want to apologize because i'm not a admin or coder and maybe all my efforts to write only this small script in my life would need one week full time reading man pages and forums but...
I don't have the money to offer me to get this time and the script I want to do seems very simple, what I want to say is my errors in the script are newbie ones...
I want to do this :
but it doesnt work.
after this works I want to this script to really do nothing if nothing changes and to send me an email if there is a changement. It takes me super long time to understand all these stuff and i'm now thinking about forgetting this and going every day to see if the page changed... This post is my last try.
If its insult to the unix community to ask this I'm sorry.
Moderator's Comments:
Please use CODE tags when displaying sample input, sample output, and code segments.
Last edited by Don Cragun; 09-06-2016 at 10:55 PM..
Reason: Add CODE tags.
Asking questions is not an insult! We are here to help you learn how to use the tools available on your system. And, your attempt was very close to working. There were only two small problems:
you can't assign a value to a positional parameter using $2=string, and
you need to use a $ to expand the contents of a shell variable.
So, if you change your script to something more like:
You should get the results you want when you run your script. The backquotes you are using for command substitution are obsolescent. The preferred method would be:
but either form will work for now.
If that works for you, you can then think about replacing the echo "change" with a command to send yourself mail. But, unless you are scheduling this script to run when you're are there to see the results, there isn't any reason to do that.
This User Gave Thanks to Don Cragun For This Post:
Thanks to show me the right way to insert code in my post and thanks for the reply,
Now with your help I don't have errors in the script but the result is wrong.
I check the two checksums are the same and the sh script give it changes.
I cannot give the url now because I need 5 posts but i can send you a capture.
---------- Post updated at 11:30 AM ---------- Previous update was at 11:24 AM ----------
OK I found my error
---------- Post updated at 11:31 AM ---------- Previous update was at 11:30 AM ----------
there is a " -"
after the second checksum the just verified now one.
---------- Post updated at 11:33 AM ---------- Previous update was at 11:31 AM ----------
I added th space and the "-" but I now have an error
I'm trying different with quotes etc.
---------- Post updated at 11:37 AM ---------- Previous update was at 11:33 AM ----------
Hello again, now i don't understand because it still give the "change" result and I checked with an echo to see the two different results and they are the same !
it gives :
we see it's the same it say "change" is there a reason for this ?
---------- Post updated at 11:47 AM ---------- Previous update was at 11:37 AM ----------
Sorry again, I find out !
with the quotes, the new checksum echo result is different thant without the quotes : one more space " -"
If i delete the quote at the first declaration of the checksum valeur its give an operator error, so i add one more space in my last checksum and it works ! !
Thank you so much for your super clear explanations !
I'm now trying to insert it in a cron and send me an email if it changes, the vps where I run this script already works for sending emails because my logwatch emails are finely received.
thank you again.
when I was a kid computers were my hobby and when I can afford it and when my usage of computers fit some of my needs I'm happy to do it myself. But I can confess actually I m jobless in japan and need money so this time I'm not defendable to spend so much time in this hobby...
A few more things to consider...
Do not use sh to run a bash script. Run it with bash:
and, to see how the script is seeing things while it is running, trace the actions your script is taking by running it with the -x and -v flags:
which will show you the strings being assigned in your assignment statements and being compared in the test command (AKA [ expression ]) in your if statement. Tracing your script is often easier and more enlightening than adding echo statements.
PS: If you just want to trace certain portions of a script (instead of the entire script), you can use:
to turn on tracing inside your script and:
to turn off tracing.
Last edited by Don Cragun; 09-07-2016 at 12:27 AM..
Reason: Add PS.
If you dig a bit deeper into md5sum (or similar commands), you may want to improve your code by taking advantage of its features. It is common to save a checksum to a file (e.g. SUM), as you don't need to hardcode it in your script, and then use that file for the comparison, and use md5sum's exit code for the if statement:
Of course you need to create and update that file regularly.
thanks, Yes I'm now thinking about doing things with more precision, creating the file with the md5 inside can be very useful, then I imagine the possibility to filter some content in the html code before making the sum.
I am getting No such file or directory if my variable contains white spaces... Is there a way to fix this?
This works
x="1.md5"
md5sum -c "$x"
This, does not
x="23\ 5\ 6\ 7\ 8\ 9\ 10.md5"
md5sum -c "$x"
md5sum: '23\ 5\ 6\ 7\ 8\ 9\ 10.md5': No such file or directory
How do I fix... (1 Reply)
I'm running on a staging server. I will need to use expect and I think ssh or scp to the other boxes.
I need to see something like this....Enter:Host 1
Enter:Host 2
Enter full directory path to compare: example /apps/acd/jboss-customer1/
Enter User Id:
Enter Password:
( Assumes... (6 Replies)
I'm trying to think of a way to compare two boxes and make sure their files will be the same. There may be extra files on one side and some on the other.
I also need to make sure the file content is identical.
So far I've gotten this to create a file
find /directorypath/ -type f -name... (3 Replies)
And not to start. I can compare files, that's easy. The problem is that I compare files in a directory, and check if these files exist in another directory. The problem is that the file names are not the same. So I have to compare with "md5sum" or something similar. How I can do?
All this in... (7 Replies)
Hello,
I need to download multiple files from an FTP server but occasionally they arrive in error so I need to perform an integrity check. I've been attempting to write a bash script that does the following:
Downloads all files including those in sub directories
Perform md5sum using... (4 Replies)
something strange is that i find the md5sum command in different linux generate different result, for example, i have tried the same file in CentOS and Rhel, The md5 results are different, it is quite headache, who know the tricks? (3 Replies)
Is it possible to call the unix command md5sum from within a C program. I am trying to write a C program that scans a directory and computes the MD5Sum of all the files in the directory. Whenever I use md5sum 'filename' I get the error 'md5sum undeclared'. Is there a header file or some library... (3 Replies)
i downloaded a Linux distribution from a FTP site today, and i found there is a file named MD5SUM in the same directory, with the following contents:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
c9a4d963a49e384e10dec9c2bd49ad73 valhalla-SRPMS-disc1.iso
41b03d068e84d2a17147aa27e704f79b ... (1 Reply)
Hi all,
I am kinda puzzled. When and Why do we use md5sum? I've read man pages for mp5sum, but didn't get anything out of it. Please, can someone explain this to me in couple of words.
Thank you all. (1 Reply)