Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty
-
-
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
-
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
-
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
Except, bash is not the place to build more functionality.
You use bash for basic stuff, or when there is no better option available.
-
@JaredBusch said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
Except, bash is not the place to build more functionality.
You use bash for basic stuff, or when there is no better option available.
technically there is no other viable option because I don't have the time to learn the alternative before I need this to be done by. the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
-
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@JaredBusch said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
Except, bash is not the place to build more functionality.
You use bash for basic stuff, or when there is no better option available.
technically there is no other viable option because I don't have the time to learn the alternative before I need this to be done by. the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
I learned the basics of python in a day or two. I bought udemy course and built a few python apps. I was able to find tutorials to build security tools like scrapers and scanners.
I've since added to these scripts and combined some of them. I'm not a python master, but it's very easy to pick up. There's also so many resources out there.
-
@IRJ said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@JaredBusch said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
Except, bash is not the place to build more functionality.
You use bash for basic stuff, or when there is no better option available.
technically there is no other viable option because I don't have the time to learn the alternative before I need this to be done by. the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
I learned the basics of python in a day or two. I bought udemy course and built a few python apps. I was able to find tutorials to build security tools like scrapers and scanners.
I've since added to these scripts and combined some of them. I'm not a python master, but it's very easy to pick up. There's also so many resources out there.
I've used python for interfacing with sensors connected to a rPi. It's easier to picup than BASH imo.
-
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
I personally hate python because of the space indentation defining code blocks. even if I always space indent my code.
But the language is simple and straightforward.
-
@JaredBusch said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
I personally hate python because of the space indentation defining code blocks. even if I always space indent my code.
But the language is simple and straightforward.
I always hated it for that, but PyCharm and other IDEs make it pretty easy. PyCharm is probably the best. I'm a fan of the JetBrains tools.
-
On the Python note, I wrote a microservice for a PoC we are doing. I wrote it in Go and it takes a JWT and some information about a secret stored in Vault and authenticates to Vault with the JWT and retrieves the secret. It was around 500-600 lines of code. I rewrote it in Python today and it was less than 40 lines of code.
-
@IRJ said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@JaredBusch said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@Obsolesce said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
@stacksofplates said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
Rather than mess with multiple arrays, you can just have a single dictionary that holds the file and status. A single function can decrypt the file. Then just save the file name and status of the decryption in that dictionary. Then loop through the dictionary and here I just print the data, but you could email it or send to Slack or whatever.
This was a quick pass so probably can be cleaned up a bit.
My reasoning behind two arrays was to keep it organized. If I do all successes in one and then all failures in the other. So I have this now:
#!/usr/bin/env bash source "/home/user1/subdirectory1/master.sh" decryptedFolderPath="/home/user2/subdirectory2/" archiveFolderPath="/home/user1/subdirectory1/archive/in/" extension=${fileName##*\.} newFileName=${fileName%.*} fileWithoutTimestamp="$newFileName.$extension" encryptedItems=$(ls encryptedFolderPath*.pgp) statusArray=() for i in $encryptedItems do gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes --decrypt "$i" | grep -q "encrypted" > "$decryptedFolderPath"/"$fileWithoutTimestamp" outPut=$(gpg --batch --homedir /home/user1/.gnupg/ --passphrase "$PASS" --list-only --list-packets --yes "$i" | grep -q "encrypted") if [ $? != 0 ]; then echo "$i is not a pgp file" statusArray+=("failed to decrypt $i, with status code $? output from pgp: $outPut") fi if [ $? == 0 ]; then statusArray+=("Succesfully Decrypted $i") echo ${#statusArray[@]} | mail -s 'report' [email protected] v=${i%.*} encryptedFile="$v" fileName=${encryptedFile##*/} @@ -27,4 +34,4 @@ continue fi done mv "$i" "$archiveFolderPath"
I think this is what you meant, right?
Well no. I meant Python can easily work with dictionaries (hash maps) vs doing multiple arrays. You'd have to switch to a hash map in Bash vs the multiple arrays.
Gotcha. Yeah it sounds more convenient it just going to take me more time to learn than I have with this current script
Isn't this the one you've been working on for like a year now? I'd say that's enough time to learn a little about scripting.
I built the original one awhile ago. Now I want to build more functionality into it. It's been static for a very long time.
Except, bash is not the place to build more functionality.
You use bash for basic stuff, or when there is no better option available.
technically there is no other viable option because I don't have the time to learn the alternative before I need this to be done by. the plan is to remake it in python later. after I convert some stuff and feel comfortable, I'll only use python
I learned the basics of python in a day or two. I bought udemy course and built a few python apps. I was able to find tutorials to build security tools like scrapers and scanners.
I've since added to these scripts and combined some of them. I'm not a python master, but it's very easy to pick up. There's also so many resources out there.
I purchased "Learn Python the Hard way". Going through it now and then experimenting.
-
@wirestyle22 said in Return Values in Bash Script and generate e-mail which shows successes, errors and if the directory is empty:
I purchased "Learn Python the Hard way". Going through it now and then experimenting.
While a good thing, if you have a working bash script just Google each line “in python”
Declare array in python
For next in python