blog'o thnet

To content | To menu | To search

Tag - utility

Entries feed - Comments feed

Wednesday 5 March 2008

Create And Remove A Remote Printer Queue (CLI)

You can easily create and remove a remote printer queue using the BSD type spooler. You just have to fill the configuration file /tmp/lp.list properly, i.e. provide the local printer name, the remote LPD server, and the remote printer queue:

# cat << EOF > /tmp/lp.list
locname1 lpdserv1 remname1
locname2 lpdserv2 remname2
EOF

Then, just run the appropriate script depending of the desired behavior. Follow, an example when removing the two queues:

# cat << EOF > /tmp/lp.remove
#!/usr/bin/env sh

for lplocal in `awk '{print $1}' /tmp/lp.list`; do
  /usr/sbin/lpshut
  /usr/bin/cancel ${lplocal} -e 2> /dev/null
  /usr/sbin/lpadmin -x${lplocal}
  /usr/sbin/lpsched -v
  sleep 1
done

exit 0
EOF
# sh /tmp/lp.remove
scheduler stopped
scheduler is running
scheduler stopped
scheduler is running
# lpstat -olocname1
no system default destination
lpstat: "locname1" not a request id or a destination

And now, the creation:

# cat << EOF > /tmp/lp.create
#!/usr/bin/env sh

while read lp; do
  eval set -- `IFS=" "; printf '"%s" ' ${lp}`
  lplocal="$1"
  lpserver="$2"
  lpremote="$3"

  /usr/sbin/lpshut
  /usr/sbin/lpadmin -p${lplocal} -orm${lpserver} -orp${lpremote} \
   -mrmodel -v/dev/null -orc -ob3 -ocmrcmodel -osmrsmodel
  /usr/sbin/accept ${lplocal}
  /usr/bin/enable ${lplocal}
  /usr/sbin/lpsched -v
  sleep 1
done < /tmp/lp.list

exit 0
EOF
# sh /tmp/lp.create
scheduler stopped
destination "locname1" now accepting requests
printer "locname1" now enabled
scheduler is running
scheduler stopped
destination "locname2" now accepting requests
printer "locname2" now enabled
scheduler is running
# lpstat -olocname1
no system default destination
printer queue for locname1
                         Windows LPD Server
                   Printer \\lpdserv1
emname1
Owner       Status         Jobname          Job-Id    Size   Pages  Priority
----------------------------------------------------------------------------
hostname: locname1: ready and waiting
no entries

That's it!

Tuesday 3 April 2007

Notes About Interesting ps(1b) Behaviour

I encounter a strange behavior using /usr/ucb/ps command recently. Normally, the COMMAND header of the output of the ps(1b) is truncated to the size of a default terminal. Adding one w flag can grow this output to 132 characters. Adding a second w flag doesn't truncate the output at all, reading the complete arguments list in the /proc/${PID}/as special file; in fact, a representation of the address space for the corresponding process. The restriction that apply here is the ability to read this file, generally the owner of the running process only.

Interestingly, at least on Solaris 8 and 9, you can print untruncated arguments list--even if you didn't have the the right to read the content of the address space special file--if the SUNWscpux package is installed. This package seems not delivered with Solaris 10.

As I remember, this package is a prerequisite for 64-bit architecture platform or you will see error messages such as Data Type Too Large if executed without it installed, but it seems to be able to behave in a very different manner as I expected.

Don't known what to think about this right now. Any though?

Monday 26 March 2007

How to Observe stderr of a Process

"How to observe stderr of a process" is a recently asked question seen on the the observability-discuss forum on opensolaris.org, ending with:

I've tried "truss", but it outputs only part of the buffers being written.

As always, a simple answer show up very quickly from a community member, in this case James Carlson:

Have you tried the "-w" option on truss? "truss -t\!all -w2" should do what you're asking.

Feel good to have lots of nice people on these lists!

Wednesday 7 June 2006

The getent(1) Utility on FreeBSD!

Yes, you got it by now: the getent(1) utility finally reached the current tree some weeks ago and has just been MFC'ed! What a good news to have this very nice tool.

I was happy to be mentioned in the commit log as one of the original demander, since getent(1) can already be found on other OSes such as Sun Solaris/OpenSolaris, NetBSD or GNU/Linux and is generally useful.

Wednesday 22 June 2005

Using ksh(1) History and Keys in Emacs Mode

In order to map the arrow keys to use history commands under the emacs mode with ksh(1), please put the following lines in the ${HOME}/.kshrc:

# Arrow keys to use history commands under the emacs command edition mode.
alias __A=`echo "\020"`   # mapping arrow key 'up'
alias __B=`echo "\016"`   # mapping arrow key 'down'
alias __C=`echo "\006"`   # mapping arrow key 'right'
alias __D=`echo "\002"`   # mapping arrow key 'left'
alias __H=`echo "\001"`   # mapping arrow key 'home'

There are two underline characters in alias commands.

To be able to get the PageUp and PageDown keys to work in vi(1), edit the ${HOME}/.exrc file and insert the following lines:

" Mapping PageUp & PageDown keys.
map  ^[[5~   ^B
map  ^[[6~   ^F

Note: comment begin with a " in .exrc, not a #.

How to enter the ^[[5~ character? You have to type Control+V, then press the PageUp key.

How to enter the ^B character? You have to type Control+Vn then press the Control+B keys.

As a last tip, here is how to change the prompt using working directory information. Using export PS1='${PWD} $ ', the behavior is as follow:

/home/jpeg $ cd
/home/jpeg $ cd /var/log
/var/log $

Using export PS1='${PWD##*/} $ ', the behavior is as follow:

jpeg $ cd
jpeg $ cd /var/log
log $