tech.gate.io blog

Sysadmin Weblog

Find:

This will describe how to render coloured output in Unix Shells.

As you probably know PS1 is the shell variable that describes the output in front of your command line. I will demonstrate on this variable how it's done, because in our environment we are using it to display the most important variables on a system (e.g. Horc instance, User, ...)

Here is how to highlight them:

FBLUE="\0033[34;1m"
NOCOL="\0033[0m"
FGREEN="\0033[32;1m"
FRED="\0033[31;1m"

PS1=`echo $FRED`"$LOGNAME@$(hostname) "`echo $FBLUE`"Blue text"`echo $FGREEN`"$anothervariable"`echo $NOCOL`" \$PWD #"

Now, that's cool ;-)

of course you could also:

echo "\0033[34;1m" BlueText; echo "\0033[0m"

 


Background:
The service contract of my old Xerox Workcenter (XM55) ran out(and I'm glad about it)!
A few weeks ago I ordered a new printer DC2250 from “Triumph Adler” aka. Kyocrea KM5050.
So all my users need to get it as the standard printer, but I'm damn lazy so the job have to be done remote.

Lately we got a second printer server, so some of the user use the printer from \\printerserver1 and a few from \\printerserver2. The \\printerserver1 crashes from time to time so I just want to add the new printer on the new printer server and delete the old machine.

Solution:
Servers I use:
\\printerserver1 #Old printer server which crash from time to time
\\printerserver2 # New stable printer server
\\dc #Have a guess, yes this is a MS Domain controller, where the AD is hosted
\\fileserver #network share for the users

old printer is Called Xerox full path \\printerserverX\Xerox
new printer is called Dc2250 full path \\printerserver2\DC2250

As I use the MS Active Directory I can use the Logonscript to get this job done.
If you ain't have a logonscript for your employees now, we will create one. My Test user is called John Dow.
I want to mount the network share, add a printer and set it to the standard printer, and delete the old printer. As you can imaging rename or deleting a printer on the server , while users got it mounted will lead you into trouble, so please don't try it.
Okay let start:

Create a new file called jdow.bat
Now open it in your favorite text editor and copy this:

net use * /del /yes
 rem delete all file shares

 net use h: \\fileserver\%USERNAME%$ /persistent:yes
 rem mount the network share of the user persistent

 net use * \\fileserver\public\sales /persistent:yes
 rem file share e.g. sales dependss on your filestructur

 rem now the printers

 rundll32 printui.dll,PrintUIEntry /q /dn /n\\printerserver1\Xerox 
 rem Printer Xerox at printerserver1 will be deleted
 
 rundll32 printui.dll,PrintUIEntry /q /dn /n\\printerserver2\Xerox 
 rem Printer Xerox at printerserver2 will be deleted

 rundll32 printui.dll,PrintUIEntry /q /in /n\\printerserver2\DC2250
 rem Printer DC2250 added

 rundll32 printui.dll,PrintUIEntry /q /y /n\\printerserver2\DC2250
 rem Printer DC2250 is now standartprinter

 rem now restart the spooler
 net stop spooler 

 net start spooler

 

Now we have a look at the “rundll32 printui.dll,PrintUIEntry” commands we use
/dn – delete a Network printer
/n – name of the printer, full path is needed
/in – install a printer (driver have to be on the printer server)
/q – Quite installation, because we don't want the user to call in to tell us they got some “strange” messages

Be sure that everything is started fine, please restart the spooler service, last two lines of the logonscript. (that should be done not a “have to”).

Script is finished,now we place it to the Standard location on the domain controller
\\dc\NETLOGON\
Make sure that the user can accesse this file, if he can't it won't work

Okay now open the
MMC (Start->Run->mmc)
File → Add/remove Snapin
Add → AD Users and Computer → Add → Close → OK
Expand your domain and search your user (usually in the OU User)
Now got to the profile tab and add the name of the *.bat file youcreatedd (e.g. jdow.bat)
Should look like this:
Image

Congratulation your done it, next time a user logon he get his network shares and the old printer are deleted and the new one appear as standard printer.

 

you need to be able to configure iptables or the sshd port on the ssh-server, in order to make this work

 

on the ssh-server:

 

unclean method:

change sshd port to 443

edit sshd_config (/etc/ssh/sshd_config) in most cases

replace Port 22 with Port 443

restart sshd

clean method:

 
check out your proxys external ip(s)

configure your browser to use your proxy

surf to http://www.whatsmyip.com.au/

repeat this after a period of time, since most companies use 2 or more external ips, switching round robin

 
now install iptables, if not already installed

run

EXTERNALIP1=xxx.xxx.xxx.xxx
EXTERNALIP2=xxx.xxx.xxx.xxx

iptables -t nat -A PREROUTING -s $EXTERNALIP1 -p tcp --dport 443 -j REDIRECT --to-port 22

iptables -t nat -A PREROUTING -s $EXTERNALIP2 -p tcp --dport 443 -j REDIRECT --to-port 22

now every attempt from externalip1/2 to port 443 on the ssh-server, ends up in port 22, where our sshd runs

 

Client configuration:

 

Windows:

for Windows use putty
just goto proxy section, choose http-proxy and enter your authentication data in the fields below
then switch to session, and put port 443 in the field next to the servers hostname

Linux:

since putty is available for linux too, the way should be the same, but for me, I want to use openssh from the kde konsole

found this tutorial:

http://www.zeitoun.net/articles/ssh-through-http-proxy/start

in short:

yum install connect-proxy

add to ~/.ssh/config:

## Outside of the firewall, with HTTPS proxy
Host my-ssh-server-host.net
  ProxyCommand connect -H proxy.free.fr:3128 %h 443
## Inside the firewall (do not use proxy)
Host *
   ProxyCommand connect %h %p

now test:

ssh my-ssh-server-host.net

 
takes a while in my case, but then login appears, working fine

 


Sometimes it's necessary to deliver "proofs", regarding the network performance.

Howto do network throughput tests, and eliminating factors like cpu time and disk i/o latency.

This section is for HPUX:

 
1.) Create a pseudo device that will deliver random data

mknod /tmp/test c 3 3
(instead you can also use /dev/random)

2.) ftp and login to the destination you want to test

ftp 172.XXX.XXX.XXX

3.)

put "|dd if=/tmp/test bs=31000 count=1000000" /dev/null

4.) Use for example link-monitor to check the throughput. This test shows the network performance, whithout distortion from disk, cpu or other components.

--------------------

Maybe someone can add, possibilities for other OS :-)

All our companies unix and linux machines send mails with "user@hostname.domain.local" in the from field over local sendmail.

I always had problems with our mailserver guys, telling me they want me to send mails with a valid exchange email address. The problem they have is, that replies to such mails end in the data nirvana, which is the case with away messages for example.

Everyone writes some mail-sending batch scripts, of course it's possible to change the from field in the script that sends the mail. But that's a lot of work for all scripts.

So I decided to set up an own mail server, that rewrites the from field to , and relays to our exchange server.

 

First I tried to set up the postfix server on AIX, compiling the latest version 2.6 was no problem. It could be started, but mail sending was not possible.
Knowing that I have 4 other ux/linux operating system platforms to try, I decided not to debug the aix-mailserver, but set it up on red hat linux 4.

up2date install postfix

 
working, perfectly.

I took one aix sap testserver (5.3), and changed the relay server to the new hostname
"linuxhostname".

/etc/mail/sendmail.cf:

DSlinuxhostname

 

Postfix configuration:
first try:

main.cf:

mynetworks = serversubnet1/24, serversubnet2/24
relayhost = exchangehost
sender_canonical_maps = regexp:/etc/postfix/canonical

(few other options to fit my security needs)
/etc/postfix/canonical:
/domain.local/ unix@maildomain.com

 


restart postfix

works!

 
but then I recognized I have a problem, now I can't determine from which host the mail was sent from. So I needed to bring the hostname to the subject or the from field.
I decided to write the hostname to the from field in the mail header, should look like this:

From: hostname <unix@maildomain.com>

 
this "hostname" is shown in the "from" column in outlook for example

 
I found another sendmail option that makes this possible:

header_checks

to main.cf:

header_checks = regexp:/etc/postfix/header_checks

 

to /etc/postfix/header_checks:

/From:.* <.*@(.*)\.domain.local>/ REPLACE From: $1 <unix@maildomain.com>

 
Note: I had to play a bit around with the regexp, not knowing that I have to use perl syntax, at first I masked () with \, and called $1 variable with \1, which was not working

 
finally got it!

cheers
Funksen

---------
Update:

meanwhile, I've found the reason, why it wasn't working on AIX, you need to run
the postfix "newaliases" command once, then the newaliases db is rewritten from postfix
now postfix runs on a two-node hacmp AIX 5.3 cluster, in local rootvg
it runs on both nodes all the time

 



First Page Page: 3/7 Last Page
1 2 3 4 5 6 7

Feeds List