Move script if upload is completed - upload

I have a script which has to move uploaded files from the first directory to the second directory.
The problem is that the script already moves the files during upload.
Anyone who can help?
#!/bin/sh
lockfile=/home/mediaze111/cronjobs/zenon_move.lock
if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
if [ "$(ls -A /home/mediaze111/domains/optimaal.fm/ZenonImport/Import1/)" ]; then
ps faux | grep -E 'UPLOAD' | grep -v 'grep' > /dev/null || mv -f /home/mediaze111/domains/optimaal.fm/ZenonImport/Import1/*.* /home/mediaze111/domains/optimaal.fm/ZenonImport/Import2/
fi
rm -f "$lockfile"
trap - INT TERM EXIT
fi

u can get the file size before upload . then check the destination file size . if same move uploaded. pul all the script in a loop so when was the same break it an move files.

Related

nginx-alpine: how to view its docker file

I have the following image: nginx:1.19.0-alpine
I want to know about its docker file. I checked https://github.com/nginxinc/docker-nginx but could not understand how to check
Basically i want to change the /docker-entrypoint.sh
Currently its
#!/usr/bin/env sh
# vim:sw=4:ts=4:et
set -e
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo "$0: Ignoring $f, not executable";
fi
;;
*) echo "$0: Ignoring $f";;
esac
done
echo "$0: Configuration complete; ready for start up"
else
echo "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
# Handle enabling SSL
if [ "$ENABLE_SSL" = "True" ]; then
echo "Enabling SSL support!"
cp /etc/nginx/configs/default_ssl.conf /etc/nginx/conf.d/default.conf
fi
exec "$#"
I want it to modify it as
#!/usr/bin/env sh
# vim:sw=4:ts=4:et
set -x -o verbose;
echo $1
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo "$0: Ignoring $f, not executable";
fi
;;
*) echo "$0: Ignoring $f";;
esac
done
echo "$0: Configuration complete; ready for start up"
else
echo "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
# Handle enabling SSL
if [ "$ENABLE_SSL" = "True" ]; then
echo "Enabling SSL support!"
cp /etc/nginx/configs/default_ssl.conf /etc/nginx/conf.d/default.conf
fi
exec "$#"
I see $1 is being passed. But no clue what to pass
Normally, the CMD from the Dockerfile is sent as parameters to the ENTRYPOINT. In the generated Dockerfile (found here for current alpine: https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine/Dockerfile), you can see that the CMD is CMD ["nginx", "-g", "daemon off;"].
So in normal use, the parameters for the entrypoint script are "nginx", "-g" and "daemon off;".
Since the first parameter is "nginx", the script will enter the if block and run the code in there.
The if is there in case you want to run a different command. For instance if you want to enter the shell and look around in the image, you could do docker run -it nginx:alpine /bin/sh. Now the parameter for the entrypoint.sh script is just "/bin/sh" and now the script won't enter the if-block.
If you want to build your own, modified version of the image, you can fork https://github.com/nginxinc/docker-nginx/ and build from your own version of the repo.
If you need the 1.19 version of the Dockerfile, you'll have to look through the old versions on the repo. The 1.19.0 version is here: https://github.com/nginxinc/docker-nginx/blob/1.19.0/stable/alpine/Dockerfile

Why is wc -l returning 0 in a sh step subshell in Jenkins/groovy

I have a Jenkins script that looks like this
stage ("Build and Deploy") {
steps {
script {
def statusCode = sh(script:"""ssh ${env.SERVER_NAME} << EOF
cd ${env.LOCATION}
git clone -b ${env.GIT_BRANCH} ${env.GIT_URL} ${env.FOLDER}
cd ${env.FOLDER}
... some other stuff goes here but isnt relevant ..
sudo docker-compose up -d --build
if [ ! \$(sudo docker container ls -f "name=config-provider-*" | wc -l ) -eq 4 ]
then
exit 1
fi
""", returnStatus:true).toString().trim()
if (statusCode == "1") {
error("At least one container failed to start")
}
}
}
}
What I want is to exit with error code 1 in the script if the number of running containers is not equal to 3 (wc -l == 4 including the header), but the if statement is evaluating true and exiting with error code 1 even though i know that the containers are successfully running.
I have tried
echo sh(script: """ssh ${env.SERVER_NAME} << EOF
echo \$(sudo docker container ls -f "name=config-provider-*" | wc -l)
""", returnStdout:true).toString()
and
echo sh(script: """ssh ${env.SERVER_NAME} << EOF
echo \$(sudo docker container ls -f "name=config-provider-*")
""", returnStdout:true).toString()
The latter outputted 4 lines within jenkins showing all of the running containers, as expected, but the former which includes "| wc -l" returned and printed out 0 in jenkins.
I have reproduced the steps of this script line by line manually from start to finish and it works as intended when not run from within jenkins.
Additionally, manually running the command:
[ ! $(sudo docker container ls -f "name=config-provider-*" | wc -l ) -eq 4 ] && echo failed
echoes nothing, and the following command returns an output of 4, which is expected.
echo $(sudo docker container ls -f "name=config-provider-*" | wc -l )

Pause a process before disk is full

Certain processes (like git gc --aggressive) take a long time to run, take up lots of disk space, and die if I run out of disk space. I'd like to pause them if the disk will run out of space soon, so I have time to free up some memory. How can I do this?
Here is an initial solution I came up with. Tested with Mac OS X. Suggestions welcome!
#!/bin/bash
# Change these variables as necessary.
FILESYSTEM="/dev/disk1"
DF=/usr/local/opt/coreutils/libexec/gnubin/df
OSASCRIPT=/usr/bin/osascript
if ! [[ -x $DF ]]; then echo "Error: $DF isn't executable."; exit 1; fi
PID=$1
STOPAT=$2
# Verify input
if [[ -n ${PID//[0-9]/} ]]; then echo "Error: The first parameter should be an integer"; exit 1; fi
if [[ -n ${STOPAT//[0-9]/} ]]; then echo "Error: The second parameter should be an integer"; exit 1; fi
RED='\033[0;31m'; PURPLE='\033[0;35m'; BLUE='\033[0;36m'
NC='\033[0m' # No Color
echo -e "Will pause the following process when there are ${PURPLE}$STOPAT${NC} bytes left on ${PURPLE}$FILESYSTEM${NC}"
PROCESS=`ps -p $PID | grep $PID`
echo -e "${BLUE}$PROCESS${NC}"
# Check every second to see if FILESYSTEM has more than STOPAT bytes left.
while true; do
left=`$DF | grep -m 1 $FILESYSTEM | tr -s ' ' | cut -d" " -f4`
echo -ne "$left bytes left\r";
if [[ $left -lt $STOPAT ]]; then
MSG="pausing process...$PID";
echo $MSG;
if [[ -x $OSASCRIPT ]]; then
$OSASCRIPT -e "display notification \"$MSG\""
fi
kill -TSTP $PID
break
fi
sleep 1s
done

Error running egrep on Solaris

Sun OS 5.8
Bash shell script
Oracle 10g database
Error 1 the command executing at the time of the error was egrep ORA-\|TNS-\|PLS-\|Error\|PLW-\|IMP-\|EXP-\|RMAN-\|SQL- alert_work.log > alert.err on line 11
The "egrep" line runs successfully when I run it manually. But in a bash script (cron job) it gets the above error. Here is the script:
#!/bin/bash
SID=$ORACLE_SID
DOMAIN=$(uname -n)
DBALIST='dbak#xxx.com'
YESTERDAY=`TZ=CST+24 date +%Y-%m-%d`
cd $ORACLE_HOME/admin/$SID/bdump
mv alert_${SID}.log alert_work.log
touch alert_${SID}.log
cat alert_work.log >> alert_${SID}.hist
egrep ORA-\|TNS-\|PLS-\|Error\|PLW-\|IMP-\|EXP-\|RMAN-\|SQL- alert_work.log > alert.err
if [ `cat alert.err|wc -l` -gt 0 ]
then
mailx -s "${DOMAIN}.${SID} ALERT LOG ERRORS FOUND" $DBALIST < alert.err.log
fi
/usr/bin/mv alert_work.log $ORACLE_HOME/admin/$SID/bdump/hist/alert_${SID}_${YESTERDAY}.log
exit
I am suspicious of your egrep regular expression, The fact that you have not quoted it, and create a script from within a Bash script leads and then run the script, leads me to think that you will end up with:
egrep ORA-|TNS-|PLS-|Error|PLW-|IMP-|EXP-|RMAN-|SQL- alert_work.log > alert.err
which is not what you intended. Try:
egrep 'ORA-\|TNS-\|PLS-\|Error\|PLW-\|IMP-\|EXP-\|RMAN-\|SQL-' alert_work.log > alert.err
That should preserve the back slashes.

Jenkins to automate deb reprepro repository creation/signing

Problem statement:
Can sign repos from inside normal terminal (also inside docker). From jenkins job, repo creation/signing fails. Job hangs.
Configuration:
Jenkins spawns docker container to create/sign deb repository.
Private and public keys all present.
gpg-agent installed on the docker container to sign the packages.
~/.gnupg/gpg.conf file has "use-agent" enabled
Progress:
Can start gpg-agent using jenkins on the docker container.
Can use gpg-preset-passphrase to cache passphrase.
Can use [OUTSIDE JENKINS]
reprepro --ask-passphrase -Vb . includedeb ${_repo_name} ${_pkg_location}
to fetch the passphrase from gpg-agent and sign the repo.
Problem:
from inside a jenkins job, the command "reprepro --ask-passphrase -Vb ..." hangs.
Code:
starting gpg-agent:
GPGAGENT=/usr/bin/gpg-agent
GNUPG_PID_FILE=${GNUPGHOME}/gpg-agent-info
GNUPG_CFG=${GNUPGHOME}/gpg.conf
GNUPG_CFG=${GNUPGHOME}/gpg-agent.conf
function start_gpg_agent {
GPG_TTY=$(tty)
export GPG_TTY
if [ -r "${GNUPG_PID_FILE}" ]
then
source "${GNUPG_PID_FILE}" count=$(ps lax | grep "${GPGAGENT}" | grep "$SSH_AGENT_PID" | wc -l)
if [ $count -eq 0 ]
then
if ! ${GPGAGENT} 2>/dev/null then
$GPGAGENT --debug-all --options ${BASE_PATH}/sign/gpg-agent.options \
--daemon --enable-ssh-support \
--allow-preset-passphrase --write-env-file ${GNUPG_PID_FILE}
if [[ $? -eq 0 ]]
then
echo "INFO::agent started"
else
echo "INFO::Agent could not be started. Exit."
exit -101
fi
fi
fi
else
$GPGAGENT --debug-all --options ${BASE_PATH}/sign/gpg-agent.options \
--daemon --allow-preset-passphrase --write-env-file ${GNUPG_PID_FILE}
fi
}
options file:
default-cache-ttl 31536000
default-cache-ttl-ssh 31536000
max-cache-ttl 31536000
max-cache-ttl-ssh 31536000
enable-ssh-support
debug-all
saving passphrase.
/usr/lib/gnupg2/gpg-preset-passphrase -v --preset --passphrase ${_passphrase} ${_fp}
finally (for completion), sign repo:
reprepro --ask-passphrase -Vb . includedeb ${_repo_name} ${_pkg_location}

Resources