I'm new on stackoverflow, and i need your help)
I'll try to describe the situation.
On a windows file-server, I have a task (running every 10 minutes) that decrypt gpg files received from an external trusted source (which encrypt files using my public key). The task run using a domain account, and decrypt files using my private key of course. Here is the script that I use to decrypt multiple files:
#echo off
FOR /R L:\IN\ %%f in (*.gpg) DO (call :subroutine %%f)
GOTO :eof
:subroutine
set filename=%1
echo %date% %time% - %filename% >> input_lst.log
gpg2 --q --batch --yes --passphrase-file "pwd.ini" -o %filename:~0,-4% -d %filename%
IF %ERRORLEVEL% EQU 0 (DEL /Q /F "%filename%") ELSE GOTO :error
GOTO :eof
:error
echo %date% %time% - %filename% >> error.log
:eof
echo %date% %time% - %filename% >> processed.log
Now, the main task is to create a batch script (no need to specify any recipient, etc) that will encrypt files in L:\OUT using the public key from external trusted source. Can someone help me? Thank you.
If you want to do something, do it by yourself))
#echo off
FOR /R L:\OUT\ %%f in (*.txt) DO (call :subroutine %%f)
GOTO :eof
:subroutine
set filename=%1
echo %date% %time% - %filename% >> encr__input_lst.log
gpg2 -r trusted#domain.com --trust-model always -o %filename%.gpg --q --batch --yes -e %filename%
IF %ERRORLEVEL% EQU 0 (DEL /Q /F "%filename%") ELSE GOTO :error
GOTO :eof
:error
echo %date% %time% - %filename% >> encr_error.log
:eof
echo %date% %time% - %filename% >> encr_processed.log
Related
This is a common question, somehow I am not able to get it working for me. I have an artifactory folder where in I store json files.
On jenkins I am supposed to download one of the jsons e.g. Myfile.json. But this has to be done only if the file exists.
Tried using below approaches:
Approach: 1)
url="https://abc/folder/Myfile.json"
if curl --output /dev/null --silent --fail -r 0-0 "$url"; then
echo "URL exists: $url"
else
echo "URL does not exist: $url"
fi
Problem: It keeps on entering the else condition even for valid URLS.
I'm executing the same using in bash shell. What is the best way to achieve this?
You can check the error code of curl request, ie
curl -s -o /dev/null -w "%{http_code}" http://www.example.org/
#!/bin/bash
url=$1
check_url=$(curl -s -o /dev/null -w "%{http_code}" ${url})
#echo $check_url
case $check_url in
[200]*)
echo "URL exists: $url"
;;
[404]*)
echo "URL does not exist: $url"
;;
*)
echo "URL error - HTTP error code $check_url: $url"
exit 1
;;
esac
Here is my code :
#echo off
for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\NCR\APTRA\Aggregate
Installer\Inventory\Aggregate\APTRA Self-Service Support" /f 06.04.01') do set "AppPath=%%~b"
echo %AppPath%
cmd /k
So when we run this batch file command prompt will open, so my requirement is when i click on Enter we need to break the FOR LOOP as the command prompt is not getting closed, Could any one please help me out ?
try with goto:
#echo off
for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\NCR\APTRA\Aggregate
Installer\Inventory\Aggregate\APTRA Self-Service Support" /f 06.04.01') do (
set "AppPath=%%~b"
goto :break
)
:break
echo %AppPath%
cmd /k
Although it sounds easy, I cannot find an answer around..
I just need to enumerate certain packets in a certain pcap file (with tshark).
e.g.:
how many packets are ipv6.ack?
how many packets are udp?
and tshark has to print just a number...
You can use the -z io,stat,0 option, e.g.:
tshark -r capture.pcap -q -z io,stat,0,"udp"
... however this will produce an IO Statistics table, not a single number.
If you have tools like wc, grep and cut available to you, you could try one or more of these solutions:
tshark -r capture.pcap -q -z io,stat,0,"udp" | grep "<>" | cut -d ' ' -f 8
tshark -r capture.pcap -Y "udp" | wc -l
If you're on Windows, and you don't have any of these tools, you could try wrapping this in a batch file, such as:
#ECHO OFF
SETLOCAL
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
IF "%1" == "" GOTO :USAGE
IF "%2" == "" (
SET TSHARK_CMD=tshark.exe -r %1 -z io,stat,0
) ELSE (
SET TSHARK_CMD=tshark.exe -r %1 -z io,stat,0,"%2"
)
FOR /F "TOKENS=6 DELIMS= " %%A in ('!TSHARK_CMD! ^| FINDSTR "^<^>"') DO (
ECHO %%A
)
GOTO :END
:USAGE
ECHO usage: printframes ^<file^> ^[filter^]
ENDLOCAL
:END
I'm trying to modify an existing script that updates Flash but the installer will not work.
I keep getting the following error.
installer: Error the package path specified was invalid: '/Volumes/Flash Player/Install Adobe Flash Player.app/Contents/MacOS/Adobe Flash Player Install Manager'.
It also does not work if I modify it to say include.pkg at the end of the filepath.
Here is the rest of the script:
#!/bin/sh
# Script to download and install Flash Player.
# Only works on Intel systems.
#
dmgfile="flash.dmg"
volname="Flash"
logfile="FlashUpdateScript.log"
echo "Updating Flash player…"
# Are we running on Intel?
if [ '`/usr/bin/uname -p`'="i386" -o '`/usr/bin/uname -p`'="x86_64" ]; then
# Get the latest version of Flash Player available from Adobe's About Flash page.
latestver=`/usr/bin/curl -s http://www.adobe.com/software/flash/about/ | sed -n '/Safari/,/<\/tr/s/[^>]*>\([0-9].*\)<.*/\1/p'`
# Get the version number of the currently-installed Flash Player, if any.
if [ -e "/Library/Internet Plug-Ins/Flash Player.plugin" ]; then
currentinstalledver=`/usr/bin/defaults read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version CFBundleShortVersionString`
else
currentinstalledver="none"
fi
echo "Installed version: $currentinstalledver"
echo "Currently last version to install: $latestver"
# Compare the two versions, if they are different of Flash is not present then download and install the new version.
if [ "${currentinstalledver}" != "${latestver}" ]; then
echo "UPDATING…"
/bin/echo "`date`: Current Flash version: ${currentinstalledver}" >> ${logfile}
/bin/echo "`date`: Available Flash version: ${latestver}" >> ${logfile}
/bin/echo "`date`: Downloading newer version." >> ${logfile}
/usr/bin/curl http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player_osx.dmg -o flash.dmg
/bin/echo "`date`: Mounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep Flash | awk '{print $1}') -quiet
/usr/bin/hdiutil attach flash.dmg -nobrowse -quiet
/bin/echo "`date`: Installing..." >> ${logfile}
/usr/sbin/installer -pkg /Volumes/Flash\ Player/Install\ Adobe\ Flash\ Player.app/Contents/MacOS/Adobe\ Flash\ Player\ Install\ Manager -target /
/bin/sleep 10
/bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep ${volname} | awk '{print $1}') -quiet
/bin/sleep 10
/bin/echo "`date`: Deleting disk image." >> ${logfile}
/bin/rm ${dmgfile}
newlyinstalledver=`/usr/bin/defaults read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version CFBundleShortVersionString`
if [ "${latestver}" = "${newlyinstalledver}" ]; then
/bin/echo "`date`: SUCCESS: Flash has been updated to version ${newlyinstalledver}" >> ${logfile}
echo "SUCCESS: Flash has been updated to version ${newlyinstalledver}"
else
/bin/echo "`date`: ERROR: Flash update unsuccessful, version remains at ${currentinstalledver}." >> ${logfile}
/bin/echo "--" >> ${logfile}
echo "ERROR: Flash update unsuccessful, version remains at ${currentinstalledver}."
fi
# If Flash is up to date already, just log it and exit.
else
/bin/echo "`date`: Flash is already up to date, running ${currentinstalledver}." >> ${logfile}
/bin/echo "--" >> ${logfile}
echo "Flash is already up to date, running ${currentinstalledver}."
fi
else
/bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}
echo "ERROR: This script is for Intel Macs only."
fi
You need to confirm that each segment of the path has permissions that would allow you to write to that directory and any below it. Save the following script into a directory in your PATH (/usr/local/bin would be appropriate) OR save it into the /tmp dir and use it with a full path.
cat pathChecker.sh
#!/bin/bash
path2chk="${#?usage:${0##*/} /path/to/check}"
if ! [[ -d "${path2chk}" ]] ; then
echo "no directory access to ${path2chk}"
echo "checking all elements anyway"
fi
echo "${path2chk}"\
| sed 's/\//\n/g' \
| while read pathElem ; do
testPath="${testPath+${testPath}/}${pathElem}"
#dbg echo "ls -ld \"$testPath\""
ls -ld "$testPath"
done
chmod +x pathChecker.sh
pathChecker.sh '/Volumes/Flash Player/Install Adobe Flash Player.app/Contents/MacOS/Adobe Flash Player Install Manager'
Should show listings like
drwxr-x-r-x ..... /Volumes
drwxr------ ..... /Volumes/Flash Player # bzt!
. . . .
Edit Also see a more generic explanation of the problem here:
How to solve Insecure world writable dir /usr in PATH,mode 040777 warning on Ruby?
IHTH
What's wrong with this code?
sudo -u replicant rsync -av -e "ssh -o 'StrictHostKeyChecking no' -i /home/replicant/.ssh/id_rsa" --exclude 'media/' --exclude 'var/' --exclude '.svn' root#$ADMIN:/var/www/ /var/www/ &> /tmp/rsync if [ $? -ne 0 ]; then
echo "date: Error rsync'ing code base from $ADMIN check /tmp/rsync" | mail -s "Rsync error!" $DEVEMAIL
echo "date: Error rsync'ing code base from $ADMIN check /tmp/rsync" >> $LOGFILE
echo "root#$ADMIN:/var/www /var/www" >> $LOGFILE
exit
fi
I keep getting this error:
Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605)
[Receiver=3.0.9]
Please help. Thanks.
Try to login directly on SSH to fix your issues, then move on to your rsync test. So start with:
ssh -o 'StrictHostKeyChecking no' -i /home/replicant/.ssh/id_rsa root#$ADMIN
Sidenotes:
don't use root for such a task
add set -eu at the start of your Bash script, so that errors will end up your script and ease debugging (for example if $ADMIN is not defined, the script will end in error)