Windows: checking file integrity with sha1 and/or md5

No Comments

Some Internet available software, normally free software, provides a checksum for file integrity testing.

What is this for? By checking that the checksum of the downloaded file matches the checksum provided on the source web site you’ll have a guarantee that the file was not modified (hacked) – unless the web site checksum was too..

So on windows how do you verify this?

There’s a tool (fciv.exe) provided by Microsoft(r) that can compute sha1 and md5 checksums. You can download it at http://support.microsoft.com/kb/841290.

After downloading it, you can extract it to c:\windows\ to make the command widely available.

Next you can verify the checksum of a downloaded file, say for example the gnupg installation package for windows. On the web site the sha1 checksum was published. Let’s verify it:

C:\external\Software\gnupg>fciv gnupg-w32cli-1.4.9.exe -sha1
//
// File Checksum Integrity Verifier version 2.05.
//
c2efad983dfe50e6d8007257bad2c76604be389a gnupg-w32cli-1.4.9.exe

Great, it matches it so the file has it’s integrity intact.

To make things easier we can create the commands sha1sum and md5sum which are normally the standard command names to check sha1 and md5.

Let’s create 2 batch files, for sha1 let’s put the following contents and save it as c:\windows\sha1sum.bat:

@echo off
fciv %1 -sha1

and for md5 let’s put the following contents and save it as c:\windows\md5sum.bat:

@echo off
fciv %1

Now we can compute the checksums by calling these commands:

C:\external\Software\gnupg>sha1sum gnupg-w32cli-1.4.9.exe
//
// File Checksum Integrity Verifier version 2.05.
//
c2efad983dfe50e6d8007257bad2c76604be389a gnupg-w32cli-1.4.9.exe

C:\external\Software\gnupg>md5sum gnupg-w32cli-1.4.9.exe
//
// File Checksum Integrity Verifier version 2.05.
//
d90854104edcb72149472a99a9392d4e gnupg-w32cli-1.4.9.exe

Bash: window size is too short, how do I change it?

No Comments

So I’m logged on to a Linux server using Bash shell over an ssh connection using Poderosa client.

When I time a long command for some reason the cursor at some point moves over to the beginning of the same line overwriting the command and everything becomes a mess. This is specially annoying while typing something you would like to cut and paste on an email for example.

So, what’s going on?

Bash has a variable that reports the number of columns setup:

$ echo $COLUMNS
80

Interesting, it is configured for 80 columns but my terminal window has 137 columns. Why is that?

There’s a Bash setting that will adapt the window size after each command:

checkwinsize
If set, Bash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS.

Let’s see what is it’s current value:

$ shopt -p | grep checkwinsize
shopt -u checkwinsize

That means it is disabled… Let’s enable it:

$ shopt -s checkwinsize

Now it is enable. Let’s check the COLUMNS value now:

$ echo $COLUMNS
137

Great!

Bash: send a running process to background

2 Comments

Say you start a process and you forget to add the & character at the end of the line to send it to the background. You don’t need to restart the process if you’re using bash (and probably other shells – check the documentation of the one you’re using).

To send the running process to the background so that you get the shell prompt back to enter more commands you have to press CTRL+Z while the process is running. The process will be temporarily suspended until you send it to the foreground with the bg [jobspec] command.

Let’s see an example:

[root@localhost log]# tail -f cron
Feb 26 11:01:01 localhost CROND[5731]: (root) CMD (run-parts /etc/cron.hourly)
Feb 26 12:01:01 localhost CROND[5743]: (root) CMD (run-parts /etc/cron.hourly)
Feb 26 13:01:01 localhost CROND[5836]: (root) CMD (run-parts /etc/cron.hourly)
Feb 26 14:01:01 localhost CROND[6097]: (root) CMD (run-parts /etc/cron.hourly)
Feb 26 15:01:01 localhost CROND[6132]: (root) CMD (run-parts /etc/cron.hourly)
Feb 27 04:26:15 localhost crond[2844]: (CRON) STARTUP (1.2)
Feb 27 04:26:16 localhost crond[2844]: (CRON) INFO (running with inotify support)
Feb 27 04:26:20 localhost anacron[2912]: Anacron 2.3 started on 2009-02-27
Feb 27 04:26:20 localhost anacron[2912]: Will run job `cron.daily’ in 65 min.
Feb 27 04:26:20 localhost anacron[2912]: Jobs will be executed sequentially
^Z
[1]+  Stopped                 tail -f cron
[root@localhost log]# jobs -l
[1]+  4107 Stopped                 tail -f cron
[root@localhost log]# bg 1
[1]+ tail -f cron &
[root@localhost log]# jobs -l
[1]+  4107 Running                 tail -f cron &
[root@localhost log]# fg 1
tail -f cron
^C
[root@localhost log]# jobs -l
[root@localhost log]#

As you see when you press CTRL+Z (or ^Z) the process is suspended (stopped). You can see the list of jobs and their state by running jobs -l. This job was given the number 1. We can then send it to the background with bg 1 or bring it back to the foreground with fg 1. At the end I kill the process by pressing CTRL+C (^C).

You can stop the job with ^Z and then send it to the background using bg with no additional arguments. Actually you can use the character % as a job name. Let’s see the following example:

# tail -f test1
line 1
line 2
^Z
[1]+  Stopped                 tail -f test1
# %1 &
[1]+ tail -f test1 &
# jobs -l
[1]+  3855 Running                 tail -f test1 &
# tail -f test2
file 2 line 1
file 2 line 2
^Z
[2]+  Stopped                 tail -f test2
# %% &
[2]+ tail -f test2 &
#
# jobs -l
[1]-  3855 Running                 tail -f test1 &
[2]+  3857 Running                 tail -f test2 &
# %-
tail -f test1
^Z
[1]+  Stopped                 tail -f test1
# jobs -l
[1]+  3855 Stopped                 tail -f test1
[2]-  3857 Running                 tail -f test2 &
# kill %1

[1]+  Stopped                 tail -f test1
# kill %2
[1]+  Terminated              tail -f test1
# jobs -l
[2]+  3857 Terminated              tail -f test2
# jobs -l

The + flag on the output of jobs -l indicates the current job and the – flag indicates the previous job. The %% and %+ names refer to the current job while %- refers to the previous job. So instead of fg 1 you can use %1. And instead of bg 1 you can use %1 &. And so on…