-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
inotifywait -m /tmp/mywallet -e create -r | | ||
while read dir action file; do | ||
path=$dir$file; | ||
echo $path; | ||
amount=$(cat $path); | ||
echo "amount = "$amount; | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Function to handle reading from a pipe | ||
read_pipe() { | ||
local dir="$1" | ||
local file="$2" | ||
local amount | ||
|
||
# Set timeout for cat command | ||
if ! amount=$(timeout 25m cat "${dir}/${file}"); then | ||
# Handle timeout - write to syslog and exit | ||
echo "Timeout occurred while reading from $file" >&2 | ||
logger "Timeout occurred while reading from $file" | ||
exit 1 | ||
fi | ||
|
||
echo "Received from $file: $amount" | ||
} | ||
|
||
# Trap SIGINT to clean up child processes | ||
trap 'kill $(jobs -p); exit' SIGINT | ||
|
||
# Watch for new pipes using inotifywait | ||
inotifywait -m /tmp/mywallet -e create -r | | ||
while read dir action file; do | ||
# Check if the created file is a named pipe | ||
if [ -p "${dir}/${file}" ]; then | ||
echo "New pipe detected: $file" | ||
# Call function to read from pipe in a background process | ||
read_pipe "$dir" "$file" & | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
# Function to handle reading from a pipe | ||
read_pipe() { | ||
local dir="$1" | ||
local file="$2" | ||
local amount | ||
local payid=$(printf "%d" "0x$file") | ||
|
||
echo $payid | ||
mysql --user=sysadmin \ | ||
--password=mypassword \ | ||
-e "UPDATE payDB.payments SET STATUS = 'WAITING' WHERE PAYID = $payid;" | ||
|
||
# Set timeout for cat command | ||
if ! amount=$(timeout 90m cat "${dir}/${file}"); then | ||
# Handle timeout - write to syslog and exit | ||
echo "Timeout occurred while reading from $file" >&2 | ||
logger "Timeout occurred while reading from $file" | ||
mysql --user=sysadmin \ | ||
--password=mypassword \ | ||
-e "UPDATE payDB.payments SET STATUS = 'TIMEOUT' WHERE PAYID = $payid;" | ||
exit 1 | ||
fi | ||
|
||
echo "Received from $file: $amount" | ||
a1=$(mysql --batch \ | ||
--user=sysadmin \ | ||
--password=mypassword \ | ||
-e "SELECT (amount) FROM payDB.payments WHERE PAYID = $payid;" | tail -n1) | ||
if [ "$amount" = "$a1" ]; then | ||
echo "amount is equal." | ||
mysql --user=sysadmin \ | ||
--password=mypassword \ | ||
-e "UPDATE payDB.payments SET STATUS = 'COMPLETED' WHERE PAYID = $payid;" | ||
else | ||
echo "amount is not equal." | ||
mysql --user=sysadmin \ | ||
--password=mypassword \ | ||
-e "UPDATE payDB.payments SET STATUS = 'FAILED' WHERE PAYID = $payid;" | ||
fi | ||
} | ||
|
||
# Trap SIGINT to clean up child processes | ||
trap 'kill $(jobs -p); exit' SIGINT | ||
|
||
# Watch for new pipes using inotifywait | ||
inotifywait -m /tmp/mywallet -e create -r | | ||
while read dir action file; do | ||
# Check if the created file is a named pipe | ||
if [ -p "${dir}/${file}" ]; then | ||
echo "New pipe detected: $file" | ||
# Call function to read from pipe in a background process | ||
read_pipe "$dir" "$file" & | ||
fi | ||
done |