Saturday, March 16, 2013

Identify available printer names

Some machines have access to more than one printer. Unless the default printer is the one you want, you need to know the name of the printer to use in the printer-related command. For instance, if you want to know the status of a printer, you execute the lpq command:

$ lpq
ml1640 is ready
no entries

ml1640 is the default printer for the machine. If you want a printer other than the default, the lpq command requires that you specify the printer name. Other commands such as lpr, and lprm behave the same way.

How do you find out the printer name that the Linux printing system will recognize?

$ lpstat -a
clp325w accepting requests since Tue 12 Mar 2013 09:42:07 PM PDT
ml1640 accepting requests since Sun 10 Mar 2013 09:22:33 PM PDT
scx3405 accepting requests since Sun 10 Mar 2013 09:24:00 PM PDT

Armed with the printer name scx3405, you simply run lpq again like this:

$ lpq -P scx3405
scx3405 is ready
no entries

If you run lpstat with the -s parameter, it will give even more information in the form of a status summary (including identifying the default printer):

$ lpstat -s
system default destination: ml1640
device for clp325w: ipp://192.168.1.22
device for ml1640: mfp:/dev/mfp4
device for scx3405: ipp://192.168.1.11

You can tell then ml1640, the default printer, is a local printer, and the rest are remote.

With lpstat, you can list the printer names that the Linux printing system can recognize.

Friday, March 8, 2013

Deciphering mysql error codes

I was tasked to upgrade the mysql server running on the Centos server.

Of course, the first thing I should do was to backup my database. I run the mysqldump command below to write out the sql statements that will re-create and populate the database tables.

# mysqldump -uroot -p -l --opt --all-databases=true > /root/mysqlall.sql
mysqldump: Couldn't execute 'show fields from `asset`': Got error 28 from storage engine (1030)

Lo and behold, I got an "error 28". What is "error 28"? The error message has no useful details that could help me troubleshoot.

The perror command came in handy in that situation.

# perror 28
OS error code  28:  No space left on device

Now, a quick df command confirmed that the hard-drive was full.

perror explains system error codes generated by mysql and the base OS(Linux).

Saturday, March 2, 2013

Auto fill in ssh client parameters

I often ssh to different servers, both at work and at home. Often, the Linux account name is different according to which server I'm logging in. Also, some servers are set up to allow ssh login through a different port than the default port 22. For instance, to login to 123.123.123.123, I need to type all this in:

# ssh -p 2222 admin_2@123.123.123.123

All of this can become human unmanageable rather quickly.

Luckily, I can set up the ssh client such that it fills in ssh login parameters such as port number and user name.

I simply type ssh followed by the IP address or hostname of the computer I want to login. ssh fills in the right port # and user name according to the IP or hostname.

# ssh 123.123.123.123
admin_2@123.123.123.123's password: 

To set it up, insert the following lines into your personal ssh client configuration file, ~/.ssh/config.

Host 123.123.123.123
   User admin_2
   Port 2222

Note that you should edit the configuration file on the ssh client computer. In other words, the setup is on the source computer from which you initiate the ssh request, not the target server that you want to login to.

Alternatively, you can make the change for all users. Insert the same lines into the system-wide ssh client configuration file. For Debian-based distributions, the file is /etc/ssh/ssh_config. You will need root access to edit that file.

After you make the edits, any new ssh client login will have the port and user name filled in automatically.

In addition to ssh, programs such as scp and sftp will also benefit from these settings.

# scp afile.txt  123.123.123.123:
admin_2@123.123.123.123's password: 
afile.txt                                  100%  198     0.2KB/s   00:00    

If you like this article, you may find this article interesting:

How to disable ssh host key checking