Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

11 April 2014

Time Counter

Time Counter

Time Counter

Create a time counter using Shell scripting.

# Create a file  time.txt  in home folder (any folder is ok). put '0' (zero) in it as second (starting value of time).

time.txt
0


# Create a  time.sh  script (in the same folder) and put this code in it.
#!/bin/sh
#file: time.sh
#description: keep track of time spend on computer.

file=time.txt

if [[ -f $file ]]; then
old_time=$( cat $file ) && new_time=$[ $old_time + 60 ] && echo $new_time > $file ;
else
echo '0' > $file ;
fi;
This script will take stored time value from  time.txt  and add 60 seconds to it when run.
So if the current stored time value is '0' (zero), it will add 60 seconds to it. and so on.


# Now we will run this script with crontab. Open Terminal and edit crontab:
crontab -e

..and add this line to the bottom of the file:
* * * * * /bin/bash ~/time.sh
This will make the  time.sh  to run and update  time.txt  simulteneously every minute.


# put this code in .bashrc file (found in home folder). with this we can check the time on terminal..
counter() {
second=$( cat ~/time.txt ) ;
day=$[ $second/86400 ] ;
hour_remain=$[ $second%86400 ] ;
hour=$[ $hour_remain/3600 ] ;
minute_remain=$[ $second%3600 ] ;
minute=$[ $minute_remain/60 ] ;

echo $day days $hour hours $minute minutes since 2014 April 12th.

}


# Open Terminal and enter counter:
0 days 0 hours 44 minutes since 2014 April 12th.


11 November 2012

automate home folder backup and software install script

unix user is notorous for oftenly changing Operating System (OS) or distro hopping. since new/increment version are realeased more frequently. it become significant / necessary to update to a newer release.

installing and configuring is time consuming if you have lots of software to install, say 30 or more. even more if you spend time playing solitaire or 0AD (no i had not played 0AD yet).

the saving grace in this situation is to create a script that will automate this work. first backup/copy your home folder (along with hidden folder).

below is the script (bash) to automate install of software after fresh install of new OS (Operating system).
the script for backing up setting from home folder is given below.



#add the name of software you want to install here seperated by [space].
cd $HOME
app_list="firefox gcolor2 gimp vlc";

for app in $app_list; do
if [[ `which $app` == "" ]]; then
echo "installing $app.....";
apt-get -y install $app; #install the app
else
echo "$app is already installed (skipping)."; #app is already
installed
fi;
done;


#script for backing up setting (from home folder).
cd $HOME ;
folder=backup ;
mkdir $folder ;
dir=$HOME/$folder/ ;

for i in `ls -A`; do
if [[ $i == .* ]]; then
if ( [[ $i == .thumbnails ]] || [[ $i == .cache ]]
|| [[ $i == .gvfs ]] || [[ $i == .local ]]
) ; #add more folder name that you don't want to backup then echo "Not copied $i";
else
echo "Copying $i";
cp -r $i $dir$i ;
fi;
fi;
done;

tar -cf backup.tar ./$folder ;
rm -r ./$folder ;




ps- sorry for my bad english. i'm still new in scripting. this is my first post.