I'm starting with shellscript, I have to do the checksum of some files, so I decided to automate things with a bash script. I made two scripts, one that uses a ls recursive in the directory set by me and ignores folders by taking only the * ('d') * files and passes it to an environment variable converting to a string, then a loop divides the converted output into rows, which are the paths of the files, passing them to another environment variable that is passed as parameter in the call of the second script, which receives this argument (file path), checksum and passes td to a file.txt, below the two scripts: first script:
#/bin/bash ###TASK3###
arquivos=$(ls -R $1 | egrep -v '^d')
for linha in $arquivos
do
bash ./task2.sh $linha
done
second script:
#/bin/bash #####TASK2####
checksum=$(hashdeep $1)
concatenado=''
for i in $checksum
do
concatenado+=$i
done
IFS=',' read -ra ADDR <<< "$concatenado"
echo
echo '----Checksum FILE:' $1
echo '----Checksum HASH:' ${ADDR[4]}
echo
echo ${ADDR[4]} >> ~/Trampo/shell_scripts/txt2.txt
The output (summarized since there are many files):
/ home / douglas / Trap / shell_scripts / (copy) .png: No such file or directory
---- Checksum FILE: (copy) .png ---- HASH Checksum:
The error is as follows: in the case here I set the directory "~ / Images", but notice that in the output it returns the path where my .sh script is with the name of the file that is in the / Images , but I'm not sending it to / Images and not to / home / douglas / Trampo / shell_scripts / (copy) .png , by even because the copy.png file is not in this same directory ...
What am I doing wrong?
Thank you!
Then friend, I tried to change the files as you recommended me and other links that I saw net out ... they did not succeed, I tried two things ..
1st:
#!/bin/bash
find $1 -type f -exec ./task2.sh {} \;
2º:
#!/bin/bash
find $1 -type f -print0 | xargs -0 -n1 ./task2.sh
I also tried:
find $1 -type f -exec bash ./task2.sh {} \;
the latter worked partially, the output of it was something like:
---- Checksum FILE: / home / douglas / Images / Geotechnology: trends and challenges - Mozilla Firefox_003.png ---- HASH Checksum:
---- Checksum FILE: /home/douglas/Images/Webcam/2016-10-27-001757.jpg ---- Checksum HASH: 40c760ff07c60b6a37d279ecdeab26b8
---- Checksum FILE: /home/douglas/Images/2eVd0f1.jpg ---- Checksum HASH: bd52f7a0a3f8845d15218f6de0436808
/ home / douglas / Images / Capture: No such file or directory / home / douglas / Trampo / shell_scripts / from: No such file or directory / home / douglas / Trap / shell_scripts / screen: No such file or directory / home / douglas / Trampo / shell_scripts / from: No such file or directory / home / douglas / Trampo / shell_scripts / 2016-10-17: No such file or directory /home/douglas/Trampo/shell_scripts/23-26-56.png: No such file or directory