Getting the correct filename from the server with wget

If you’ve used the GNU wget utility, you know that often when wget downloads files, it saves files with odd file names. Sometimes these are long garbled filenames or the name ‘download’.

To get wget to honour the correct filename from the server, the method is to use wget with the –content-disposition flag.

Eg:

wget https://github.com/i-MSCP/imscp/archive/1.1.11.tar.gz --content-disposition

Unfortunately, –content-disposition does not have an alias, and it becomes easily a chore, typing that repeatedly. Some people create an alias for wget and use:

alias wget='wget --content-disposition'

The more proper method is to set the option in the configuration file in your home directory:

#cat ~/.wgetrc
content-disposition = on

Now wget will download files to the correct name.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Removing the drum from toner-drum assembly on a Brother DCP-7060D

https://www.youtube.com/watch?v=-ZgfY1ow7LE


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

How to install Brother DCP-7060D on Ubuntu

Visit the Linux driver(.deb) download page for Brother DCP-7060D.
Download the “Driver Install Tool”
Run the following:

gunzip linux-brprinter-installer-2.0.0-1.gz
sudo su 
bash linux-brprinter-installer-2.0.0-1

Now you will asked: “Input model name ->”
Type: DCP-7060D
and type Y to all the prompts until you reach this question:
“Will you specify the DeviceURI ?”
Here, specify No if you have the printer connected to USB (7060D has no direct network support).

After installation continues, try to print a test page. It didnt succeed for me and I found that Linux was “waiting for the printer to respond”.

At this point, I opened “Printers” from Unity, deleted the printer that was automatically installed, and clicked on “Add new printer”, and chose the entry corresponding to DCP-7060D. Now the test page worked.

Troubleshooting:
For some odd reason, on my new Ubuntu 14.04 installation, www.brother.com could not be resolved by the installation script (wget timeout). I had to manually add the following line to /etc/hosts:

23.55.58.66 www.brother.com

Installing Scanner drivers:
Download the scanner DEBs from the download page

dpkg -i --force-all brscan4-0.4.3-2.amd64.deb 
dpkg -i --force-all brscan-skey-0.2.4-1.amd64.deb
dpkg -i --force-all brother-udev-rule-type1-1.0.0-1.all.deb

After installation, CUPS can be managed from http://localhost:631/printers

Manufacturer instructions for installation:
Login as a superuser ( or use “sudo” option if it is required )

Check if pre-required procedures are completed
For Debian/Ubuntu 64 bit
For Ubuntu8.04 or greater

Download drivers
Download LPR driver and cupswrapper driver.

Install LPR driver and cupswrapper driver
Turn on the printer and connect the USB cable.
Open the terminal and go to the directory where the drivers are.
Install LPR driver.The install process may take some time. Please wait until it is complete.
Command (for dpkg) : dpkg -i –force-all (lpr-drivername)

Install cupswrapper driver.The install process may take some time. Please wait until it is complete.
Command (for dpkg) : dpkg -i –force-all (cupswrapper-drivername)

Check if the LPR driver and cupswrapper driver are installed
Command (for dpkg) : dpkg -l | grep Brother

Depending on the connection type you are using (USB or Network), follow one of the steps below.

(for USB Connection)
Open a web browser and go to “http://localhost:631/printers”.
Check if the Device URI of your printer is “usb://Brother/(your printer’s model name)”

If the device URI is different from the example above, please go to “Modify Printer” of your printer to select proper device and driver.
If your printer is not listed on “http://localhost:631/printers”, please go to “http://localhost:631/admin” and click “Add printer” and select proper device and driver.

(for Network Connection)

Open a web browser and go to “http://localhost:631/printers”.
Click “Modify Printer” and set following parameters.
– “LPD/LPR Host or Printer” or “AppSocket/HP JetDirect” for Device
– lpd://(Your printer’s IP address)/binary_p1 for Device URI
– Brother for Make/Manufacturer Selection
– Your printer’s name for Model/Driver Selection
Try a test print
Open a text editor, write something and select “print” from the menu.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Install VNC on Debian

For a KDE Desktop run via VNC,

On the server:

apt-get install kde-plasma-desktop tightvncserver xtightvncviewer

Debian Wiki states that for a full KDE installation, one needs to do this:

aptitude install ~tkde-desktop

For LXDE:

apt-get install task-lxde-desktop

Create a user:

useradd -c "Tightvnc user" -m -r -s /bin/bash vncuser
sudo -iu vncuser bash
unset XAUTHORITY
vncserver

Now, create a vncserver instance:

vncserver :1 -geometry 1356x758 -depth 16 -pixelformat rgb565

If you weren’t prompted for a password, set a password for vnc with:

vncpasswd

If you need to reset the server:

tightvncserver -kill :1

Now, edit the file: /root/.vnc/xstartup

Find the line:

gnome-session &

and replace it with:

startkde &

if you prefer kde.

For lxde, the file looks like this:

#cat /root/.vnc/xstartup
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
lxterminal &
/usr/bin/lxsession -s LXDE &

Optionally setup an alias in .bashrc, and assign:

alias startvnc='vncserver :1 -geometry 1366x676 -depth 16 -pixelformat rgb565'
alias killvnc='tightvncserver -kill :1'
#alias startvnc='vncserver :1 -geometry 1356x758 -depth 16 -pixelformat rgb565'

On Windows, install TightVNC, and connect to url: yourserverip:5901

To enable Copy Paste between Windows and the VNC instance, try this:
Add the following lines to /root/.vnc/xstartup before /usr/bin/lxsession -s LXDE & :

vncconfig  -nowin &
export XKL_XMODMAP_DISABLE=1
autocutsel -fork

The final file for LXDE now looks like this:

#cat /root/.vnc/xstartup
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1

vncconfig  -nowin &
export XKL_XMODMAP_DISABLE=1
autocutsel -fork

/etc/X11/Xsession
lxterminal &
/usr/bin/lxsession -s LXDE &

Now you can copy something in Windows and paste into Tightvnc.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Midnight commander (mc) shows garbled text characters instead of graphics

Midnight commander (mc) shows garbled text characters instead of graphics

On a Debian ssh shell running via Putty on Windows 8, I started getting this weird display on midnight commander:

MWSnap009 2013-05-06, 21_29_08

 

To fix this,

In Putty>Load Session

Putty>Window>Translation>Remote character set>UTF8

MWSnap010 2013-05-06, 21_29_55

Also export the following variable in your .bashrc file:

NCURSES_NO_UTF8_ACS=1

Save the session. Exit and restart Putty. mc is fixed now.

MWSnap011 2013-05-06, 21_31_41

Credits: 
http://www.andremiller.net/content/getting-midnight-commander-line-drawing-work-putty

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Pipe grep to less with color

You need to use the grep –color=always option with less -R

Eg:

#grep -inr 'robots' * --color=always | less -R

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Using ‘less’ command with special character interpretation

Using ‘less’ command with special character interpretation

It is possible to use perl or bash for ascii colorization of output and send them to a log file. The advantage is that you can highlight errors, info messages etc in a log and view them later. The obvious disadvantage is that if your log file runs to a few thousand Kilobytes or more, you have to use the less command and the results are less than awesome.

For example,

A command like this:

tail -n 50 /root/wordpress_update.log

Normally results in:

MWSnap004 2013-04-02, 09_24_36

 

If less was used for piping:

tail -n 50 /root/wordpress_update.log | less

It now looks like this:

MWSnap005 2013-04-02, 09_27_21

Which is very ugly.

The solution is to use the -R switch in less:

tail -n 50 /root/wordpress_update.log | less -R

Which results in what you needed:

MWSnap006 2013-04-02, 09_29_23


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Adding auto complete for apt-get install

Question:

I have noticed that while on Ubuntu, if I type the following:

mc

and it isnt installed, I get the message below:

The program 'mc' is currently not installed. You can install it by typing: sudo apt-get install mc

However in Debian, that is not available. It just gives a “-bash: /usr/bin/mc: No such file or directory” message. How can I implement the same functionality in bash command line on Debian? Yes, I know that if it is package suggestion that I want, I can simply do a regex search using *apt-cache search*. However I was hoping for the simpler suggestion immediately on typing the name of the program.

As per discussions, the functionality is provided by the package command-not-found. However even after installing it, and also installing bash-completion package, this isnt available on the Debian bash shell.

Answer:

The suggestions are definitely provided by the package command-not-found.

However after installing the package, one needs to run the following command once to initialize the database:

update-command-not-found

After doing this, bash starts providing suggestions to install the correct package.

$htop
Could not find the database of available applications, run update-command-not-found as root to fix this
htop: command not found

$update-command-not-found
Downloading complete file http://ftp.de.debian.org/debian/dists/squeeze/Contents-i386.gz
I: Writing data for ftp.de.debian.org_debian_dists_squeeze_Contents-i386.gz ... . done

$htop
The program 'htop' is currently not installed. You can install it by typing:
apt-get install htop
htop: command not found

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Add bash autocompletion for your own script

Let your script be named utstart, and accepts any of the following arguments: start, stop, install, uninstall.

As an example, you would perhaps run your script like this from bash:

./utstart start

You would like to autocomplete start, by pressing TAB key like this:

./utstart s[TAB]

This is easy.

Prerequisite:

Install bash-completion package.

apt-get install bash-completion

Now create a new script like this:

#!/bin/bash
_utstart()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="start stop install uninstall"

    if [[ ${cur} == * && ${COMP_CWORD} -eq 1 ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _utstart -o filenames utstart

Note that we have added the options “start stop install uninstall” in the script. Note also the last line contains the name of the function in our auto completion script, and also the name of our main bash script, which accepts autocompletion entries.

Once done, copy this file to /etc/bash_completion.d/utstart-auto.

Now you may change permissions on it to make it executable.

chmod +x /etc/bash_completion.d/utstart-auto

Source it with:

. /etc/bash_completion.d/utstart-auto

Now try the following:

./utstart s[TAB}

 

You will now be presented with start and stop as options.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Cannot sftp, can ssh and scp

I’d noticed an issue on my server where it allows me to login with ssh, or transfer files with scp or rsync, but would not allow me to use Filezilla to transfer files using sftp protocol

My /var/log/auth.log showed the following:

Mar  7 05:31:03 gambit sshd[28323]: Server listening on 0.0.0.0 port 22.
Mar  7 05:31:03 gambit sshd[28323]: Server listening on :: port 22.
Mar  7 05:31:09 gambit sshd[28310]: pam_unix(sshd:session): session closed for user root
Mar  7 05:31:14 gambit sshd[28329]: Accepted password for root from 59.93.41.155 port 55173 ssh2
Mar  7 05:31:14 gambit sshd[28329]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar  7 05:31:15 gambit sshd[28329]: subsystem request for sftp
Mar  7 05:32:52 gambit sshd[28323]: Received signal 15; terminating.
Mar  7 05:32:52 gambit sshd[28352]: Server listening on 0.0.0.0 port 22.
Mar  7 05:32:52 gambit sshd[28352]: Server listening on :: port 22.
Mar  7 05:32:55 gambit sshd[28329]: pam_unix(sshd:session): session closed for user root
Mar  7 05:33:00 gambit sshd[28358]: Accepted password for root from 59.93.41.155 port 55198 ssh2
Mar  7 05:33:00 gambit sshd[28358]: subsystem request for sftp

I checked my sshd_config at /etc/ssh/sshd_config. The line I was looking for was:

PermitRootLogin yes

However that was already set.

So I was in a delimma. I couldnt find out at all, what the issue was, until I read this comment by mdpc on Server Fault, where he says:

Another issue that I have noticed, is that if your login startup files generate any sort of output, scp and sftp fail. Be sure you bracket things that output to the terminal in your startup scripting using a test on the variable $?prompt if it is non-zero you talking with a terminal.

This made me remember that I wasnt getting this issue immediately after installed a new OS, however only after I’ve worked on it for a while. So I understood that it was because I had .bashrc set to output a few things. So if .bashrc output anything to the terminal, an sftp would fail.

Moving .bashrc fixed the issue.

In fact, once I became aware of the issue, it was easy to find that this situation was rather well documented, in no less than the openssh

http://www.openssh.org/faq.htmlFAQ

2.9 – sftp/scp fails at connection, but ssh is OK.

sftp and/or scp may fail at connection time if you have shell initialization (.profile, .bashrc, .cshrc, etc) which produces output for non-interactive sessions. This output confuses the sftp/scp client. You can verify if your shell is doing this by executing:

ssh yourhost /usr/bin/true

If the above command produces any output, then you need to modify your shell initialization.

There are many solutions you can use, and all of them involve checking what kind of shell you’re running. If it’s a non-interactive shell like xterm, you execute .bashrc. If it’s filezilla, you dont.

So you first rename .bashrc to .bashc_real

Then you insert one of the following code into a new file .bashrc:

if [ "$TERM" = "xterm" ]
then
   source .bashc_real
fi

OR

if [ "$TERM" != "dumb" ]
then
   source .bashc_real
fi

OR

if [ "$SSH_TTY" ]
then
   source .bashc_real
fi

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.