Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Saturday, June 27, 2015

GIT New Branch Creator


#!/usr/bin/env bash
echo "present working directory is:";
pwd; 
echo ; echo "enter your GIT project dir, followed by [ENTER]:"
read directory
cd $directory;
echo "present working directory is:";
pwd; 
echo 'git branch -vvv;';
git branch -vvv;
echo "this is the branch you are on [ENTER]";  
read a 
echo ; echo "enter branch you want to hard reset and use as new branch, followed by [ENTER]:"
read branch
git fetch; 
git checkout  $branch; 
git reset --hard origin/$branch;
echo ; echo "enter the new branch name, followed by [ENTER]:"
read newBranch
git checkout -b $newBranch $branch;
git push -u origin $newBranch;
echo 'git branch -vvv;';
git branch -vvv;
echo "this is the branch you are on [ENTER]"; 

Monday, September 23, 2013

Super simple Bash script for math drills, first grade math level. Addition only, can easily change in script.

#!/usr/bin/env bash
clear
voice="say -v Princess"
while true
do
clear
a=`jot -r 1  1 10`
b=`jot -r 1  1 10`
echo "$a + $b = WHAT?"
$voice $a plus $b equals WHAT
READ
c=$(expr $a + $b)
echo $c
$voice $c
READ
done

Wednesday, August 1, 2012

MAMP Scripts PHP and Apache logs, starting MySQL

PHP logs for MAMP

#!/usr/bin/env bash
cat /Applications/MAMP/logs/php_error.log
echo "        /Applications/MAMP/logs/php_error.log"

Apache logs for MAMP

#!/usr/bin/env bash
cat /Applications/MAMP/logs/apache_error.log
echo "        /Applications/MAMP/logs/apache_error.log"

Start MAMP mysql on command line

echo "cd /Applications/MAMP/Library/bin";
echo "hit enter";
READ;
cd /Applications/MAMP/Library/bin;
echo "/Applications/MAMP/Library/bin/mysql -uroot -p";
echo "hit enter";
READ;
/Applications/MAMP/Library/bin/mysql -uroot -p;

Friday, April 13, 2012

Basic ssh login script

#!/usr/bin/env bash
ip="127.0.0.1";
u="joe";
p="2222"
webport="8080";
while true;
do
echo "http://$ip:$webport":
echo "ssh -p $p $u@$ip";
read -p "press enter";
ssh -p $p $u@$ip;
done

Tuesday, May 31, 2011

Slackware SlackBuilds download and install workflow

I'm using Slackware (13.37), and wrote this blog entry to help Slackware newbies like myself understand the workflow dealing with tar files downloaded from http://slackbuilds.org/.

In this example we work with installing the json-py package. The bash scripting is generalized, will work with any package install.

mkdir ~/sources
cd ~/sources
  # [ in browser ] go to http://slackbuilds.org/repository/13.37/python/json-py/
  # [ in browser ] to download Slackbuild json-py.tar.gz, save it to ~/sources 
filename=`basename *.tar.gz .tar.gz`; tar -xf *.tar.gz; rm *.tar.gz; cd $filename;
  # [ in browser ] to download Source download json-py-3_4.zip, save it to ~/sources 
installpkg `./$filename.SlackBuild | grep Slackware | awk '{ print $3 }'`;

The lines of script above give a sense of the workflow. A smarter workflow is provided in the shell script below.

~/sources/eternalDownload.sh 
#!/usr/bin/env bash

while true
do
echo "go to slackbuilds.org and download your SlackBuild tar.gz file, hit enter when done.";
read;
filename=`basename *.tar.gz .tar.gz`; tar -xf *.tar.gz; rm *.tar.gz; 
cd $filename; pwd;
echo "go to slackbuilds.org and download your source code file, hit enter when done.";
read;
installpkg `./$filename.SlackBuild | grep Slackware | awk '{ print $3 }'`;
cd ..;
done

Thursday, October 23, 2008

shabang line maker

#!/usr/bin/env bash
me=`whereis env | cut -d" " -f2`
echo "#!"$me" "$1 > $2
echo "" >> $2
echo "" >> $2
chmod 0777 $2
ls $2

Saturday, October 18, 2008

Bash: Generate an HTML table

#!/bin/bash
clear
typeset -i row col rows cols
let row=1 col=1 rows=10 cols=10

echo "<table>";
 while ((row<=rows)) ; do
          echo -n "<tr>"
          while ((col<=cols)) ; do
                echo -n "<td>";
                echo -n $col;
                echo -n "</td>";
                let col++
               done
 let col=1
 echo "</tr>";
 let row++
 done
echo "</table>";

Tuesday, December 25, 2007

Bash: Check if file exists

<source_code>
#!/bin/bash
FILENAME=$1
if [ -f $FILENAME ]; then
echo "Size is $(ls -lh $FILENAME | awk '{ print $5 }')"
echo "Type is $(file $FILENAME | cut -d":" -f2 -)"
echo "Inode number is $(ls -i $FILENAME | cut -d" " -f1 -)"
echo "$(df -h $FILENAME | grep -v Mounted | awk '{ print \
"On",$1", \
which is mounted as the",$6,"partition."}')"
else
 echo "File does not exist."
fi
</source_code>

Monday, December 24, 2007

Bash iteration over list with command line argument


<source_code>
#!/bin/bash
LIST="
Anyone
Everyone
Someone
"
for item in ${LIST}
do
echo ${1} ${item} 
done
exit 0;
</source_code>

>./listing.sh hello
hello Anyone
hello Everyone
hello Someone

Telnet Into All in IP Range


<source_code>
#!/bin/bash
host=0;
IP=10.0.2;
scheme=telnet;
while [ $host -lt 255 ]
do
${scheme} ${IP}.${host};
let "host = host+1";
done
</source_code>

Sunday, December 23, 2007

Recursive Bash Program


< source_code>
#!/bin/bash
LIMIT=$1
if [ $2 ]
then
CELL=$2
else
CELL=[] 
fi 
#******************
print_horizontal_line()
{
ME=0
while [ $ME -lt $LIMIT ] 
do
echo -n $CELL 
let "ME= ME+1"
done
}
#******************

#******************
print_vertical_line()
{
ME2=0
while [ $ME2 -lt $LIMIT ] 
do
print_horizontal_line  
echo     
let "ME2= ME2+1"
done
}
#******************
print_vertical_line;
let "LIMIT= LIMIT/2"
if [ $LIMIT -le 0 ]
then
exit
else
$0 $LIMIT $CELL
fi
exit
</source_code>

This short program to the above serves to demonstrate some basic bash programming syntax and a (very) basic use of recursion. If the program is run on the command line as:

lancemiller$ recursive_bash 4
[][][][]
[][][][]
[][][][]
[][][][]
[][]
[][]
[]
In shell programming the arguments are numbered
$0  $1   $2   $3   $4 ....etc 
recursive_bash 4
 ^             ^
 |             |
$0             $1

The recursive_bash program is going to take $1 (numeral 4 in this example) and perform some math and print a certain amount of characters as a result. First $1 is assigned to the variable LIMIT. Math and print statements occur using $LIMIT. $CELL is the character that will be printed. Argument $2 is optional. Example:

lancemiller$ recursive_bash 4 cat
catcatcatcat                   ^
catcatcatcat                   |
catcatcatcat              arg $2   
catcatcatcat
catcat
catcat
cat

$LIMIT is divided by 2.-> let "LIMIT= LIMIT/2" Then the recursive moment comes in recursive_bash at the line that says: 
$0 $LIMIT $CELL
$0 is the program itself(recursive_bash). It is called over and over till
let "LIMIT= LIMIT/2" results in zero. When $LIMIT is equal or less than zero the program exits.