Open Source Software and Linux:

unix

Apr 14 2009   1:06AM GMT

University of Utah gets hit by conficker worm



Posted by: John Little
Conficker, university of utah, windows, Linux, unix, virus, operating system

Over 700 computers were hit by the most recent release of the conficker worm at the University of Utah. Computers included those at the University’s three hospitals.

The worm was first detected on Thursday on some of the school’s computers. By Friday it had hit the school’s computers at the three hospitals, medical school, and colleges of nursing, pharmacy and health.

University officials don’t believe that any patient data or medical records were compromised. According to officials those are protected “in a deeper way”. That begs the question of what exactly does that mean? Is that the only data that is virus protected? Is it on Linux or Unix?

The IT staff at the school shut off internet access for up to 6 hours Friday in an effort to isolate the worm. The staff worked over the weekend to cleanup the damage caused by the outbreak. Kind of gives real meaning to the saying “An ounce of prevention is worth a pound of cure” doesn’t it?

Mindy Tueller of the university’s office of information technology said all faculty and students should take steps to make sure they are protected. The virus does not infect Macs.

Or Linux, Unix or any other OS besides Windows :-)

“It can do a lot of bad things,” Tueller said. “Every university member should be concerned about this if they’re using Windows-based devices.”

Interesting. Ms. Tueller and school officials apparently recognize that the problem is the OS but apparently don’t want to do anything about it. How much does that attitude cost the school?

-j

Jan 25 2009   1:22AM GMT

Using the Korn Shell with Linux



Posted by: John Little
korn shell, bash, Linux, unix, scripting

My current consulting gig requires that I use the Korn Shell and modify Unix scripts so that they will work with Linux. While the Korn Shell has many comparable characteristics of BASH there are some distinct differences-or at least ones that I’ve never seen in BASH.

The first difference that I noticed is tab completion. For example let’s say that I issue the command

ls /home/jlittle

and hit the tab key to see the files and directories. The output that you see will be in this format

ls /home/jlittle/
1) CentOS-5.2-x86_64-bin-DVD/
2) Desktop/
3) Documents/
4) Video call snapshot 8.png
5) bin/
6) ffmpeg.cfg

At this point you can either choose a number and hit the tab key or type in the first couple of letter of what you want to see or do. The complete output when using the number would look like this

ls /home/jlittle/<tab>
1) CentOS-5.2-x86_64-bin-DVD/
2) Desktop/
3) Documents/
4) Video call snapshot 8.png
5) bin/
6) ffmpeg.cfg
ls /home/jlittle/Desktop/<2tab>
Project-timeSheet.ods Skype.desktop

Typing 2 tab and the tab completion gives us the listing of the /home/jlittle/. Kind of a cool way of doing tab completion don’t you think?

You should also not use the “test” built-in that is available in bash. In bash the test built-in is the same as the “[" built-in. In other words don't use

if test $# -gt 0; then

instead use:

if [ $# -gt 0 ]; then

The korn shell also prefers the use of double brackets syntax “[[ ]]” instead of single brackets. This adds additional operators such as && and ||:

if [[ $# -gt 0 && $? -eq 0 ]]; then

You can use && and || to construct shorthand for an “if” statement in the case where the if statement has a single consequent line:

[ $# -eq 0 ] && exit 0

The Korn Shell is a powerful tool that can make your job easier. Since it’s creation several features have been added while maintaining backwards compatibility with the Bourne shell. The Korn shell can also be used as a programming language which gives it a distinct advantage of typical Unix and Linux shells.

Give ksh a whirl. I haven’t even scratched the surface of what the Korn shell can do for your scripting. If you are used to scripting with Bash then learning the Korn shell should only have a mild learning curve while presenting you with additional scripting power and speed.

-j


Jan 24 2009   8:01PM GMT

Setting script variables using the if..then statement



Posted by: John Little
Linux, unix, ksh, korn shell, bash, if..then, variable

Recently I found myself wanting to set some variables in a script that I was writing using the if..then statement. I am using the Korn shell but this is bash compatible.

I wanted to do this as the variable command changed depending on if the script was running on Linux, HP-UX or AIX. This saved a ton of typing the same test over and over throughout the script which is about 600 lines.

The basic form of the script is

if [[ $STRING != string ]]; then
VARIABLE=string1
else
VARIABLE=string2
fi

As you can see the if statement is built around the VARIABLE rather than VARIABLE=if statement. Doing it in that form either won’t return any output or give you output that is not useful.

A real world example

VENDOR=$(uname)
if [ $VENDOR != "Linux" ];then
BACKUPHEADER=log “$(date ‘+%D %T’) Checking header.”
else
BACKUPHEADER=/bin/logger -t “VALIDATE LINUX BACKUP: $(date ‘+%D %T’) Checking header.”
fi
[code]
As you can see from the above the Unix command for sending output to syslog is log and is logger on Linux. Now imagine having to run various tests throughout the script and sending the output to syslog depending on the OS. As I mentioned, it saved quite a bit of typing.

Hope this helps you somewhere!

-j


Sep 6 2008   8:05AM GMT

Squid proxy server quick start



Posted by: John Little
http, windows, Linux, unix, ftp, https, squid, proxy, centos, web proxy, proxy cache, squid.conf, Yum

Here is a quick start plan for installing the squid-cache.org proxy server. Squid is a caching proxy server that uses HTTP, HTTPS and FTP for caching web pages from the internet. By caching web pages locally the squid server helps you save on bandwidth and increases page response time for web surfing.

When you first open the squid configuration file it can be overwhelming with over 4000 lines. Many of these are comments but there are still hundreds of configuration choices. I am going to reduce these down to a solid foundation which will get you up and running quickly. This will give you some time to study the other configuration choices that may be necessary for your use. For most people some form of the configuration entries that we use here will be enough to control and proxy your web access.

Squid can be installed on Linux, Unix or Windows. For our purposes here we are installing on Centos 5.x.

Let’s get started:

Install the Squid package
yum install squid

cd to the configuration directory
cd /etc/squid

The default squid config file contains over 4000 lines. Remove the comments so that the file
is a workable size
Copy the squid.conf file to dist.conf.squid to preserve the comments for reference
cp squid.conf dist.squid.conf
The following sed command edits the squid.conf file in place removing comments and empty lines
sed -i.tmp '/^#/d; /^$/d' squid.conf
This will produce a file that contains the following entries:


http_port 3128
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
access_log /var/log/squid/access.log squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
coredump_dir /var/spool/squid

After doing this you will need to add some lines to the squid file for your environment

vim squid.conf
visible_hostname
acl our_networks src / /
as in 192.168.1.0/24 192.168.2.0/24
http_access our_networks

Save your changes and exit the squid.conf file.

Create the squid cache directories in /var/spool/squid
quid -z

Set squid to start on reboot
chkconfig squid on

Start squid
service squid start

This should work out of the box after pointing the clients to the correct proxy server and port.

Additional configuration directives can be issued through the /etc/sysconfig/squid file and the /etc/init.d/squid script.

I hope this helps you get squid up and running quickly. Enjoy!

-j