please use code tags for code
https://www.linuxquestions.org/quest....php?do=bbcode
Code:
User=$1
Password=$2
Host=$3
Path=$4
for i in $(grep "^packages" $filename | cut -d= -f2 | tr ',' ' '); do
# ^ undefined var.
for file in $(find /home/user/ftpuser -maxdepth 1 -iname -type f | while read ITEM; do
case "${ITEM}" in
*.ear|*.war) if [ -e "${ITEM%.ear}.config" -o -e "${ITEM%.war}.config" ]; then
echo got .config
fi
;;
esac
); do # this is very confused
echo /apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs ${i} -input ../ftpuser/ -output ../reports/ "$file"
# ^ is either "got" or ".config"
cp "${file}" /home/user/ftpuser/scanned/
# ^ is either "got" or ".config"
scp "${file}" (directory to the specified path from the user,needs login details)
# ^ is either "got" or ".config"
done
sleep 60
done
I'm not clear on what you want to do
I think $i should feature in your find command
the for file, is redundant
the echo, cp and scp should be inside the case, on the condition that the .config exists
many holes in the below, as I do not really understand what you need
Code:
#!/bin/bash
User=$1
Password=$2
Host=$3
Path=$4
filename=/path/to/somefile
for i in $(grep "^packages" $filename | cut -d= -f2 | tr ',' ' '); do
find /home/user/ftpuser -maxdepth 1 -iname -type f -iname "*$i*" | while read ITEM; do
case "${ITEM}" in
*.ear|*.war) if [ -e "${ITEM%.ear}.config" -o -e "${ITEM%.war}.config" ]; then
echo got .config
echo /apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs ${i} -input ../ftpuser/ -output ../reports/ "$ITEM"
cp "${ITEM}" /home/user/ftpuser/scanned/
scp "${ITEM}" (directory to the specified path from the user,needs login details)
fi
;;
esac
done
sleep 60
done
http://tldp.org/LDP/Bash-Beginners-Guide/html/
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashGuide
re-read, and re-wrote
you don't need the case, case is really just a more convenient way of doing nested if statements
to make more readable, used $Windup for most of the command line
used the User var in the find
I assumed /reports and /ftpuser were on the root ( if not 'build' them with reports_dir=/home/${User}/reports )
Still needs 'work', I have left out error capture/reporting ( added hint )
Code:
#!/bin/bash
User=$1
Password=$2 # bad!
Host=$3
Path=$4
filename=/path/to/somefile
Windup="/apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar"
for Package in $(grep "^packages" $filename | cut -d= -f2 | tr ',' ' '); do
find /home/${User}/ftpuser -maxdepth 1 -iname -type f -iname "*${Package}*[ew]ar" | while read File;do
if [[ -e "${File%.[ew]ar}.config" ]]; then
echo got .config
$Windup -javaPkgs ${Package} \
-input "/ftpuser/${File%.[ew]ar}.config" \
-output "/reports/${File%.[ew]ar}.report" || echo this is a failure hint
cp "${File}" "/reports/${File%.[ew]ar}.report" /home/${User}/ftpuser/scanned/ || echo and so is this
fi
done
done
and you don't want to pass the password on the command line
Code:
cat > nolongersecret.sh <<EOF
for i in {1..20};do sleep 5;done
EOF
bash nolongersecret.sh ThisIsMyPasswd &
ps -ef | grep nolongersecret.sh
anyone can see it