Download and upload aem packages using shell script

Using shell script you can download packages from source instance and upload into destination instance

# packages.txt 
service pack: aem-service-pkg-6.5.4.zip 
AEM forms: AEM-Forms-6.5.4.0-OSX-6.0.138.zip
#!/bin/bash
FILE="/home/prahlad/packages.txt"
TEMP="/home/prahlad/temp"
crx_packmgr_path="/etc/packages/adobe/cq650/servicepack"
source="localhost:4502"
dest="localhost:4503"
# create temp folder.
mkdir $TEMP
# start loop to read file and execute command for each line .
while IFS= read -r line
do
package_name=`echo "$line" | awk '{split( $0,array, ":"); print array[2]}'`
# download packages from source server.
echo $source $crx_packmgr_path $package_name $TEMP | awk '{print("curl -u admin:admin http://"$1 "" $2 "/" $3 " > " $4 "/" $3)}' | sh
wait $!
# upload and install package into destination server.
echo $package_name $dest $TEMP | awk '{print("curl -u admin:admin -F file=@" $3 "/" $1 " -F name="$1" -F force=true -F install=true http://"$2"/crx/packmgr/service.jsp")}' | sh
wait $!
done <"$FILE"

Shell script example | cpu usage monitoring

#!/bin/sh
memuse=$(ps -p $(pidof java) -o %mem | awk ‘{if(NR>1)print}’);
thresholdVal=50;
if [ $memuse >  $thresholdVal ]; 
then
    message=”Memory usage for jboss service on application server exceeded threshold.nCurrent use is $memuse %.”
    echo -e $message | mail -s “Alert : Memory monitoring UHMB” “prahlad20@gmail.com”;
fi
cpuuse=$(ps -p $(pidof java) -o %cpu | awk ‘{if(NR>1)print}’);
if [ $cpuuse > $thresholdVal ];
then
    message=”CPU usage for jboss service on application server exceeded threshold.nCurrent use is $cpuuse %.”;
    echo -e $message | mail -s “Alert : CPU monitoring UHMB” “prahlad20@gmail.com”;
fi

FTP

What is FTP?


FTP stands for File Transfer Protocol. The protocol specifications were written by Abhay Bhushan and published as Request for Comments (RFC) 114 in April 1971.

The File Transfer Protocol (FTP) is the standard network protocol used for the transfer of computer files between a client and server on a computer network. FTP is built on a client-server model architecture and uses separate control and data connections between the client and the server.

FTP command and usage


Command

Usage

ls List files on the remote server
get file Download file
mget file* Download multiple files. You can use wildcards (*) to download all files with specific filename pattern. For example mget *.log to will download all files with extension .log
put file Upload file
mput file* Upload multiple files. You can use wildcards (*) the same way they’re used with mget
cd Navigate to a path on the remote server. Example: cd /tmp/uploads
lcd Navigate to a path on the local server (your machine). Example: lcd /home/myuser
bin Choose binary mode for file transfer
ascii Choose ascii mode for file transfer
bye Exits the current session

linux command | linux command cheat sheet

File Management
  • ls – List files and folders
  • cd – Change directory
  • pwd – Present working directory
  • mkdir – Make a new empty directory
  • rmdir – Remove an empty directory
  • cp – Copy files or directory
  • rm – Remove files or directory
  • mv – Move files or directory / Rename files or directory
  • find – Find files or folders bases on name, data, size, owner or other parameters
  • touch – make a new blank files
Permissions
  • chown – Change ownership of files / directories
  • chgrp – Change group ownership of files / directories
  • chmod – Change permission of files / directories
  • groups – Reports the groups you belong to
  • id – Reports your username, user-id, group(s) and groupid(s)
Resource Monitoring
  • w – See who logged in on your system and what they are doing.
  • who – See who logged in on which shell and time.
  • uname – display the system information like(machine name, version, hostname).
  • hostname – display your system hostname.
  • top – See the top resource hungry processes.
  • ps – Process schedule / status.
  • df – See how much disk space is free.
  • du – Report numbers and size of files on disk.
Printing
  • lpr – send text or post script files to the printer.
  • lpq – view the print queue.
  • lprm – Remove your print jobs.
Job Control
  • whereis – Display full path and installation path of commands.
  • which – Display the full path of commands.
  • ctrl+z – Suspend the current job
  • bg – Put a suspended job in the background.
  • fg – Bring a suspended job into the foreground.
  • kill – Kill a process
Filtering/Searching
  • grep – Search for sub strings in a file or pipeline.
  • awk – Pattern searching in a folder or within a file.
  • sed – Sed is a Stream Editor used for modifying the files in unix (or linux). Whenever you want to make changes to the file automatically.
  • sort – Sort lines alphabetically or numerically.
  • wc – Count lines, word and characters.
  • cat – Catalog a file.
  • more – Teminal bases text viewing program.
 

Find matching files and folder and rename it 

find . -name “clientlib_*” | awk ‘{print(“mv “$1 ” ” $1)}’ | sed ‘s/clientlib_//2’ | sh