1

1 - 3   [3]

Everything's Gone Virtual!

Also relates to Operating Systems

Firstly apologies to anyone who has felt the urge to follow my blog with such a sporadic posting of entries over the last 18 months. Becoming a dad has compelled me to reassign my priorities and blogging time has really been under the kosh.

Anyway, time is of the essence so I must not ramble. Virtualization is the name of the game currently and I have been hard at work and play test driving a broad array of Linux platforms on both a Windows Vista host and a Tiger host. Since last posting my excitement at discovering VMWare Player back in May I have upgraded to Fusion and Workstation and started building virtual operating systems from scratch using ISO boot disks. I have one goal in mind and that is to create my development nirvana - a perfect setup of multiple displays and desktops that will allow me to meet my objectives in the quickest possible time using the minimum number of actual platforms.

I will come back to this in the coming weeks and discuss what desktops and operating systems I have gone for. Watch this space…

Posted on Jul 24, 2008 at 19:43:10.

Verify Sudo in Script Execution

Also relates to Apache and OSX

Earlier I was setting up a couple of shell scripts to allow me to quickly switch between PHP versions on the Apache web server and enable/disable my unit testing environment in OS X. Along the lines of:


apachectl stop
httpd -f /usr/local/php5/httpd.conf

Since such scripts must be run as root user I wanted to concote a little script to check I had used sudo to run the commands (as I have a habit of forgetting!). Firstly I came up with the following:


#!/bin/sh
# verify-su
umask 222
touch /tmp/user-status
echo `whoami` 2> /dev/null >| /tmp/user-status
if [ $? -ne 0 ] ; then
  if [ $# -eq 0 ] ; then
    "This command must be run with root privileges!"
  else
    "$1 must be run with root privileges!"
  fi
  exit 1
fi

\rm /tmp/user-status

exit 0

A file is created with read only permissions (by temporarily changing umask) and then the script attempts to write to it. The output redirection to file will only succeed if the script is run as root (the superuser).

In running this without the rm command I discovered that a script executed with sudo will return root from the whoami command instead of the user name I am currently logged in with. So this could actually be simplified considerably to:


if [ `whoami` != 'root' ] ; then
  # etc … 
  exit 1
else
  exit 0
fi

There is always a simpler way to do things!

Posted on Jun 20, 2005 at 20:12:51. [Comments for Verify Sudo in Script Execution- 1]

First Steps Into Shells

Also relates to Shell Scripting

I have had Cygwin sitting on my Windows OS for some time now, and only utilised it occasionally to get to grips with the intricacies of the UNIX system. I finally decided the other day to put it to work a bit, and start learning Shell scripting. The main incentive being that my text editors and macros were not reducing the workload enough in reworking old web sites to improved standards and accessibility levels. In only a few days graft, I am already revelling in the offerings of text utilities like SED, AWK, TR and GREP, and I have a few reasonable scripts to rework the content of some of my HTML files.

As a little challenge to learn the language a bit, I have been working at a simple text routine to crunch Javascript files down for bandwidth optimisation. A while ago I tried a Windows tool called JSCrucher (I cannot remember where I found this, but there are plenty of tools available in this Google Search), but this repeatedly crashed my system, and the tools available in the Bash shell appear to make this task relatively easy. While Javascript source files are well spaced, indented and commented for easy editing, the uploaded file can have all comments and whitespace removed. However, a space does need to remain in variable and function declaration (eg var obj or function validate()). As an initial shell command, I came up with this little pipeline:


# place a dot separator in variable declaration
sed -e 's/var /var./g'               
# place a dot separator in function declaration
    -e 's/function /function./g'     
# remove all comments
    -e 's///.*[a-z]$//' testfile | 
# remove all whitespace
tr -d '[:space:]' |                  
# remove dot separator in variable declaration
sed -e 's/var./var /g'               
# remove dot separator in function declaration
    -e 's/function./function /g'     

As a newcomer to Bash and Co., I am sure there are more efficient ways to go about this, but it is always nice to get out of the blocks with a new language. I can see the UNIX text tools getting significant use over the coming months. Hope to play around with this a bit more, improve it and get it into a shell script which also creates a source backup of the Javascript file and can run batches.

Posted on Oct 15, 2003 at 05:45:26. [Comments for First Steps Into Shells- 1]

Breadcrumbs Trail

[ Home ] -> TW Blog -> UNIX
Site Map

The Severn Solutions website achieves the following standards:

[ XHTML 1.0 ] [ CSS 2 ] [ WAI AA ] [ Bobby AA ]

Page compiled in 0.028 seconds