#Sample shell script to move files from source to destination directory if the count (no. of files) in #source is more than 450.
#!/bin/bash
SourceDirectory=/opt/files/Other/Temp
TargetDirectory=/opt/files/Other/Taxonomy
#SourceDirectory=/opt/scripts/move_test/src
#TargetDirectory=/opt/scripts/move_test/trg
counter=0
TG_count1=$(ls $TargetDirectory | wc -l)
echo $TG_count1
file_count=$(expr 450 - ${TG_count1})
echo "Source folder : $SourceDirectory"
echo "Number of files possible to move : $file_count"
for foldercreation_file in `ls -tr $SourceDirectory`; do
if [ $counter -lt $file_count ];then
mv $SourceDirectory/$foldercreation_file $TargetDirectory
echo "$foldercreation_file => $TargetDirectory"
counter=$((counter+1))
else
counter=0
break
fi
done
------------------------------------------------------------------------------------------
Shell script for handling a partial automated deployment instead of manual:
REPO:
Source_AlfJARFile=/home/id/alf-jar-file
Destination=/opt/alfresco/modules/platform/
cp "$Source_AlfJARFile" "$Destination"
stopServer="/opt/alfresco/./alfresco.sh stop"
startServer="/opt/alfresco/./alfresco.sh start"
echo "Attempting to find process id for Alfresco. . ."
tomcatPID=$(ps -ef | grep java | grep -v grep | grep -v restart | awk '{print $2}')
if [ "$tomcatPID" == "" ]
then
echo "Tomcat does not appear to be running . . ."
else
echo "Killing Tomcat using process id of $tomcatPID . . ."
kill -9 $tomcatPID
echo "Waiting for process $tomcatPID to end . . ."
while ps -ef | grep $tomcatPID > /dev/null; do sleep 1; done
echo "Process $tomcatPID has ended . . ."
fi
sleep 10
Source_ADF_WAR=/home/id/adf-db-service.war
Destination_ADF_WAR=/opt/alfresco/tomcat/webapps/
ADF_WAR=/opt/alfresco/tomcat/webapps/adf-db-service.war
ADF_WAR_EXPLODED=/opt/alfresco/tomcat/webapps/adf-db-service
if [ -f "$ADF_WAR" ]
then
rm -rf "$ADF_WAR"
fi
if [ -d "$ADF_WAR_EXPLODED" ]
then
rm -rf "$ADF_WAR_EXPLODED"
fi
sleep 10
cp "$Source_ADF_WAR" "$Destination_ADF_WAR"
echo "Attempting to start Tomcat via $startScript . . ."
#nohup $startScript &
$startServer
echo "Process complete . . ."
SHARE/ADF:
#!/bin/bash
Source_ADF_ZIPFolder=/home/id/angular
Destination_ADF_ZIPFolder=/opt/share/tomcat/webapps/
Source_ShareJARFile=/home/id/alfresco-share.jar
Destination=/opt/share/modules/share/
#cp "$Source_ShareJARFile" "$Destination"
#stopServer="/opt/share/./alfresco.sh stop"
#startServer="/opt/share/./alfresco.sh start"
#$stopServer
#echo "Attempting to find process id for Alfresco. . ."
#tomcatPID=$(ps -ef | grep java | grep -v grep | grep -v restart | awk '{print $2}')
#if [ "$tomcatPID" == "" ]
#then
# echo "Tomcat does not appear to be running . . ."
#else
# echo "Killing Tomcat using process id of $tomcatPID . . ."
# kill -9 $tomcatPID
# echo "Waiting for process $tomcatPID to end . . ."
# while ps -ef | grep $tomcatPID > /dev/null; do sleep 1; done
# echo "Process $tomcatPID has ended . . ."
#fi
#sleep 10
ADF_ZIP_FOLDER=/opt/share/tomcat/webapps/angular
if [ -d "$ADF_ZIP_FOLDER" ]
then
rm -rf "$ADF_ZIP_FOLDER"
fi
sleep 10
cp -r "$Source_ADF_ZIPFolder" "$Destination_ADF_ZIPFolder"
#echo "Attempting to start Tomcat via $startScript . . ."
#$startServer
echo "Process complete . . ."
Folder_Creation
#!/bin/bash
Scripts_Dir=/alfresco/scripts
SuccessLogs_Dir="/alfresco/services/logs/Success Logs"
FailureLogs_Dir="/alfresco/services/logs/Failure Logs"
#mkdir -p will create all missing folders in the path
if [ ! -d "$Scripts_Dir" ]
then
mkdir -p "$Scripts_Dir"
fi
if [ ! -d "$SuccessLogs_Dir" ]
then
mkdir -p "$SuccessLogs_Dir"
fi
if [ ! -d "$FailureLogs_Dir" ]
then
mkdir -p "$FailureLogs_Dir"
fi
Source_JAR=/home/id/SpringBatch.jar
Destination=/alfresco/services/
Existing_File=/alfresco/services/SpringBatch.jar
Existing_File_BAK=/alfresco/services/SpringBatch.jar.BAK
sleep 2
mv "$Existing_File" "$Existing_File_BAK"
cp "$Source_JAR" "$Destination"
echo "Process complete . . ."
------------------------------------------------------------------------------------------
Shell script to find files under /alfresco dir which are older than 7 days, delete them and log the name of the deleted files in delete_files.log:
#!/bin/bash
find /alfresco -maxdepth 3 -mtime +7 -exec rm -rvf {} \; > /alfresco/delete_files.log
-----------------------------------------------------------------
Shell script to copy files from source folder to dest folder recursively; also where the source/dest path contains space in it; after moving, renaming the file by appending current datetime to the file name:
SourceDirectory1=/alfresco/ABC
TargetDirectory1=/alfresco/XYZ
for foldercreation_file1 in `ls -tr $SourceDirectory1`; do
mv $SourceDirectory1/$foldercreation_file1 $TargetDirectory1
echo "$foldercreation_file1 => $TargetDirectory1"
done
SourceDirectory2="/alfresco/Folder Space Name"
TargetDirectory2="/alfresco/Folder Space Name Service"
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
echo "DATE_WITH_TIME"
IFS=$'\n' # make newlines the only separator
for foldercreation_file2 in `find "$SourceDirectory2" -maxdepth 5 -type f` ; do
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
echo "$foldercreation_file2"
NAME=${foldercreation_file2##*/}
echo $NAME
mv "$foldercreation_file2" "$SourceDirectory2"/"$DATE_WITH_TIME"_$NAME
echo "$foldercreation_file2 => $TargetDirectory2"
done
for foldercreation_file2 in `ls -tr "$SourceDirectory2"`; do
#DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
mv "$SourceDirectory2"/$foldercreation_file2 "$TargetDirectory2"
echo "$foldercreation_file2 => $TargetDirectory2"
done
--------------------------------------------------------------------------------------------------------
Alternate command of nohup - to start/run a service in background:
1) cd /opt/services/
2) screen -S <KEYWORD_CONTAINING_JAR_NAME>
3) java -jar <JAR_NAME>
4) Ctrl + A + D
--------------------------------------------------------------------
diff between touch and vim
Vi - a programmers text editor.
It can be used to edit all kinds of plain text. It is especially useful forediting programs.Mainly used by Unix programmers. Nowadays, knowing to work in vi is an added advantage for Oracle DBA's /Developers.
Touch- change file timestamps
Update the access and modification times of each FILE to the current time.
Scenario 1 :
I u feel to create a empty file means, go for touch command.
Scenario 2:
You have alredy created a file with some contents,Then if you are thinking to change only the timestamp of that old file to current timestamp Then just dotouch filename. It will change the file timestamp to current timestamp without changing any contents in the file.
------------------------------------------------------------
diff between vi and vim:
"vi" is an text editor from the early days of Unix. ... Vim (" vi improved") is one of this editors. As the name suggest it adds lot of functions to the original vi interface. In Ubuntu Vim is the only vi-like editor installed by default, and so vi actually starts Vim by default.
--------------------------------------------------------------
use of apachectl:
apachectl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache httpd daemon.
use of apachectl -t
Run syntax tests for configuration files only. The program immediately exits after these syntax parsing tests with either a return code of 0 (Syntax OK) or return code not equal to 0 (Syntax Error). If -D DUMP_VHOSTS is also set, details of the virtual host configuration will be printed. If -D DUMP_MODULES is set, all loaded modules will be printedInfo: http://publib.boulder.ibm.com/httpserv/manual70/p...
#!/bin/bash
SourceDirectory=/opt/files/Other/Temp
TargetDirectory=/opt/files/Other/Taxonomy
#SourceDirectory=/opt/scripts/move_test/src
#TargetDirectory=/opt/scripts/move_test/trg
counter=0
TG_count1=$(ls $TargetDirectory | wc -l)
echo $TG_count1
file_count=$(expr 450 - ${TG_count1})
echo "Source folder : $SourceDirectory"
echo "Number of files possible to move : $file_count"
for foldercreation_file in `ls -tr $SourceDirectory`; do
if [ $counter -lt $file_count ];then
mv $SourceDirectory/$foldercreation_file $TargetDirectory
echo "$foldercreation_file => $TargetDirectory"
counter=$((counter+1))
else
counter=0
break
fi
done
------------------------------------------------------------------------------------------
Shell script for handling a partial automated deployment instead of manual:
REPO:
Source_AlfJARFile=/home/id/alf-jar-file
Destination=/opt/alfresco/modules/platform/
cp "$Source_AlfJARFile" "$Destination"
stopServer="/opt/alfresco/./alfresco.sh stop"
startServer="/opt/alfresco/./alfresco.sh start"
echo "Attempting to find process id for Alfresco. . ."
tomcatPID=$(ps -ef | grep java | grep -v grep | grep -v restart | awk '{print $2}')
if [ "$tomcatPID" == "" ]
then
echo "Tomcat does not appear to be running . . ."
else
echo "Killing Tomcat using process id of $tomcatPID . . ."
kill -9 $tomcatPID
echo "Waiting for process $tomcatPID to end . . ."
while ps -ef | grep $tomcatPID > /dev/null; do sleep 1; done
echo "Process $tomcatPID has ended . . ."
fi
sleep 10
Source_ADF_WAR=/home/id/adf-db-service.war
Destination_ADF_WAR=/opt/alfresco/tomcat/webapps/
ADF_WAR=/opt/alfresco/tomcat/webapps/adf-db-service.war
ADF_WAR_EXPLODED=/opt/alfresco/tomcat/webapps/adf-db-service
if [ -f "$ADF_WAR" ]
then
rm -rf "$ADF_WAR"
fi
if [ -d "$ADF_WAR_EXPLODED" ]
then
rm -rf "$ADF_WAR_EXPLODED"
fi
sleep 10
cp "$Source_ADF_WAR" "$Destination_ADF_WAR"
echo "Attempting to start Tomcat via $startScript . . ."
#nohup $startScript &
$startServer
echo "Process complete . . ."
SHARE/ADF:
#!/bin/bash
Source_ADF_ZIPFolder=/home/id/angular
Destination_ADF_ZIPFolder=/opt/share/tomcat/webapps/
Source_ShareJARFile=/home/id/alfresco-share.jar
Destination=/opt/share/modules/share/
#cp "$Source_ShareJARFile" "$Destination"
#stopServer="/opt/share/./alfresco.sh stop"
#startServer="/opt/share/./alfresco.sh start"
#$stopServer
#echo "Attempting to find process id for Alfresco. . ."
#tomcatPID=$(ps -ef | grep java | grep -v grep | grep -v restart | awk '{print $2}')
#if [ "$tomcatPID" == "" ]
#then
# echo "Tomcat does not appear to be running . . ."
#else
# echo "Killing Tomcat using process id of $tomcatPID . . ."
# kill -9 $tomcatPID
# echo "Waiting for process $tomcatPID to end . . ."
# while ps -ef | grep $tomcatPID > /dev/null; do sleep 1; done
# echo "Process $tomcatPID has ended . . ."
#fi
#sleep 10
ADF_ZIP_FOLDER=/opt/share/tomcat/webapps/angular
if [ -d "$ADF_ZIP_FOLDER" ]
then
rm -rf "$ADF_ZIP_FOLDER"
fi
sleep 10
cp -r "$Source_ADF_ZIPFolder" "$Destination_ADF_ZIPFolder"
#echo "Attempting to start Tomcat via $startScript . . ."
#$startServer
echo "Process complete . . ."
Folder_Creation
#!/bin/bash
Scripts_Dir=/alfresco/scripts
SuccessLogs_Dir="/alfresco/services/logs/Success Logs"
FailureLogs_Dir="/alfresco/services/logs/Failure Logs"
#mkdir -p will create all missing folders in the path
if [ ! -d "$Scripts_Dir" ]
then
mkdir -p "$Scripts_Dir"
fi
if [ ! -d "$SuccessLogs_Dir" ]
then
mkdir -p "$SuccessLogs_Dir"
fi
if [ ! -d "$FailureLogs_Dir" ]
then
mkdir -p "$FailureLogs_Dir"
fi
Source_JAR=/home/id/SpringBatch.jar
Destination=/alfresco/services/
Existing_File=/alfresco/services/SpringBatch.jar
Existing_File_BAK=/alfresco/services/SpringBatch.jar.BAK
sleep 2
mv "$Existing_File" "$Existing_File_BAK"
cp "$Source_JAR" "$Destination"
echo "Process complete . . ."
------------------------------------------------------------------------------------------
Shell script to find files under /alfresco dir which are older than 7 days, delete them and log the name of the deleted files in delete_files.log:
#!/bin/bash
find /alfresco -maxdepth 3 -mtime +7 -exec rm -rvf {} \; > /alfresco/delete_files.log
-----------------------------------------------------------------
Shell script to copy files from source folder to dest folder recursively; also where the source/dest path contains space in it; after moving, renaming the file by appending current datetime to the file name:
SourceDirectory1=/alfresco/ABC
TargetDirectory1=/alfresco/XYZ
for foldercreation_file1 in `ls -tr $SourceDirectory1`; do
mv $SourceDirectory1/$foldercreation_file1 $TargetDirectory1
echo "$foldercreation_file1 => $TargetDirectory1"
done
SourceDirectory2="/alfresco/Folder Space Name"
TargetDirectory2="/alfresco/Folder Space Name Service"
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
echo "DATE_WITH_TIME"
IFS=$'\n' # make newlines the only separator
for foldercreation_file2 in `find "$SourceDirectory2" -maxdepth 5 -type f` ; do
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
echo "$foldercreation_file2"
NAME=${foldercreation_file2##*/}
echo $NAME
mv "$foldercreation_file2" "$SourceDirectory2"/"$DATE_WITH_TIME"_$NAME
echo "$foldercreation_file2 => $TargetDirectory2"
done
for foldercreation_file2 in `ls -tr "$SourceDirectory2"`; do
#DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S%N"`
mv "$SourceDirectory2"/$foldercreation_file2 "$TargetDirectory2"
echo "$foldercreation_file2 => $TargetDirectory2"
done
--------------------------------------------------------------------------------------------------------
Alternate command of nohup - to start/run a service in background:
1) cd /opt/services/
2) screen -S <KEYWORD_CONTAINING_JAR_NAME>
3) java -jar <JAR_NAME>
4) Ctrl + A + D
--------------------------------------------------------------------
diff between touch and vim
Vi - a programmers text editor.
It can be used to edit all kinds of plain text. It is especially useful forediting programs.Mainly used by Unix programmers. Nowadays, knowing to work in vi is an added advantage for Oracle DBA's /Developers.
Touch- change file timestamps
Update the access and modification times of each FILE to the current time.
Scenario 1 :
I u feel to create a empty file means, go for touch command.
Scenario 2:
You have alredy created a file with some contents,Then if you are thinking to change only the timestamp of that old file to current timestamp Then just dotouch filename. It will change the file timestamp to current timestamp without changing any contents in the file.
------------------------------------------------------------
diff between vi and vim:
"vi" is an text editor from the early days of Unix. ... Vim (" vi improved") is one of this editors. As the name suggest it adds lot of functions to the original vi interface. In Ubuntu Vim is the only vi-like editor installed by default, and so vi actually starts Vim by default.
--------------------------------------------------------------
use of apachectl:
apachectl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache httpd daemon.
use of apachectl -t
Run syntax tests for configuration files only. The program immediately exits after these syntax parsing tests with either a return code of 0 (Syntax OK) or return code not equal to 0 (Syntax Error). If -D DUMP_VHOSTS is also set, details of the virtual host configuration will be printed. If -D DUMP_MODULES is set, all loaded modules will be printedInfo: http://publib.boulder.ibm.com/httpserv/manual70/p...
No comments:
Post a Comment