Last active
July 8, 2019 01:16
-
-
Save rayonhunte/091fd4b64ca8806c2ba6969358e8ae54 to your computer and use it in GitHub Desktop.
commando CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reqTotal=$(wc -l $1 | awk -F' ' '{print $1}') | |
post=0 | |
get=0 | |
push=0 | |
put=0 | |
while IFS= read -r line; do | |
method=$(echo $line | cut -d' ' -f6) | |
if [ $method == '"POST' ] | |
then | |
post=$[$post + 1] | |
# echo $post | |
elif [ $method == '"GET' ] | |
then | |
get=$[$get + 1] | |
fi | |
done < "$1" | |
printf "Total Number of Request %s\n" $reqTotal | |
printf "Total Number of Post Request %s\n" $post | |
printf "Total Number of GET Request %s\n" $get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo $'\e[1;33m' Welcome to Commando !!!$'\e[0m' | |
echo $'\e[1;33m' Please Chose from below menu Options $'\e[0m' | |
# run prep script | |
./preCommando.sh | |
#script functions | |
# install npm function | |
function npmInint(){ | |
echo "################# start action ##################" >> commando_log 2>&1 | |
date >> commando_log 2>&1 | |
echo "npm install / command option 1" >> commando_log 2>&1 | |
npm install >> commando_log 2>&1; cd cashout; npm install >> ../commando_log 2>&1; cd .. >> commando_log 2>&1 | |
} | |
# start application | |
function startApp(){ | |
echo $(./sysd.sh) | |
} | |
# command options list | |
commands=" | |
Install-npm-packages | |
Start-App | |
Stop-App | |
Restart-App | |
Download-Updates | |
Show-status | |
Generate-Report | |
Help | |
" | |
select option in $commands; | |
do | |
case $REPLY in 1) | |
#print chosen option | |
echo $option | |
echo "Install Started" | |
npmInint | |
echo "Install Completed" | |
;; | |
2) | |
echo $option | |
startApp | |
echo "App Started" | |
;; | |
3) | |
echo $option | |
sudo systemctl stop nodeserver | |
echo "App Stoped" | |
;; | |
4) | |
echo $option | |
sudo systemctl restart nodeserver | |
echo "App restarted" | |
;; | |
5) | |
echo $option | |
cd cashout; git pull | |
;; | |
6) | |
echo $option | |
sudo systemctl status nodeserver | |
;; | |
7) | |
echo $option | |
read -p "Please enter log file name " logfile | |
inFile='server/'$logfile | |
if [ -e $inFile ] | |
then | |
./alltheparse.sh $inFile | |
else | |
echo "No such log file" | |
fi | |
;; | |
8) | |
echo "Commands" | |
count=1 | |
for o in $commands | |
do | |
echo $count")"$o | |
count=$[$count+1] | |
done | |
echo "Control -C to exit commando" | |
echo "Call Rayon for help with all the things" | |
;; | |
*) | |
echo "Sorry Invalid Option" | |
;; | |
esac | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Node.js Express server | |
After=network.target | |
[Service] | |
Enviorment=NODE_PORT=3001 | |
Type=simple | |
User=root | |
ExcStart=/usr/bin/node /home/rhunte/GitHub/commando_cli/server/server.js | |
Restart=on-failure | |
RestartSec=10 | |
[Install] | |
WantedBy=mulit-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#command prep file | |
#store application path | |
ogPath=$(pwd) | |
#check of bash profile | |
isBashrc=$(cd ~; ls -la | grep '.bashrc' -c) | |
# if file exist 0 if file does not exist | |
if [ $isBashrc -ne 1 ] | |
then | |
touch ~/.bashrc | |
echo "alias commando='cd $PWD; ./commando.sh'" >> ~/.bashrc | |
echo $'\e[1;33m' bashrc file added to your home $'\e[0m' | |
echo $'\e[1;33m' Commando alias added $'\e[0m' | |
exec bash | |
else | |
# bashrc file exist | |
isCommando=$(grep 'commando' -c ~/.bashrc) | |
# does commando alias exist | |
if [ $isCommando -ne 1 ] | |
then | |
# add commando alias to bashrc file | |
echo "alias commando='cd $PWD; ./commando.sh'" >> ~/.bashrc | |
echo $'\e[1;33m' Commando added to your bashrc file $'\e[0m' | |
exce bash | |
else | |
# commando alias exist in the file infrom user | |
echo $'\e[1;33m' You can now just run commando to start the commando cli$'\e[0m' | |
fi | |
fi | |
#switch bash to application path | |
cd $ogPath | |
# check for log file | |
isLog=$(ls | grep 'commando_log' -c) | |
# echo $isLog | |
if [ $isLog -ne 1 ] | |
then | |
touch commando_log | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#store application path | |
ogPath=$(pwd) | |
# check for system d file | |
isSystemd=$(ls /etc/systemd/system/ | grep 'nodeserver' -c) | |
#node file | |
nodeFile=/etc/systemd/system/nodeserver.service | |
echo $isSystemd | |
if [ $isSystemd -ne 1 ] | |
then | |
# create systemd service file | |
sudo touch $nodeFile | |
# write to new file | |
sudo sh -c "echo [Unit] > $nodeFile" | |
sudo sh -c "echo Description=Node.js Express server >> $nodeFile" | |
sudo sh -c "echo After=network.target >> $nodeFile" | |
sudo sh -c "echo '' >> $nodeFile" | |
sudo sh -c "echo [Service] >> $nodeFile" | |
sudo sh -c "echo Enviroment=NODE_PORT=3001 >> $nodeFile" | |
sudo sh -c "echo Type=simple >> $nodeFile" | |
sudo sh -c "echo User=root >> $nodeFile" | |
sudo sh -c "echo ExecStart=/usr/bin/node $ogPath/server/server.js >> $nodeFile" | |
sudo sh -c "echo Restart=on-failure >> $nodeFile" | |
sudo sh -c "echo '' >> $nodeFile" | |
sudo sh -c "echo RestartSec=10 >> $nodeFile" | |
sudo sh -c "echo '' >> $nodeFile" | |
sudo sh -c "echo [Install] >> $nodeFile" | |
sudo sh -c "echo WantedBy=multi-user.target >> $nodeFile" | |
# reload systemctl to load new service | |
sudo systemctl daemon-reload | |
fi | |
#start app no matter what | |
sudo systemctl start nodeserver | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment