Recent Notes

Displaying keyword search results 1 - 3
Created by magnum on March 28, 2011 11:51:53    Last update: March 28, 2011 11:52:36
dd by default does not give you any indication of progress. You may be wondering what's going on when you are copying a big file and it's taking a long time. You may start dd in the background and send it SIGUSR1 periodically to view progress. However, I think pv is more convenient. $ pv /dev/cdrom | dd of=./cdrom.img bs=64k 1.19... I've seen code like the following in the wild. But it's fragile code at best since it depends on the text output of fdisk. In fact, it doesn't work for most systems since fdisk reports in GB not MB. Plus the regex is unnecessarily complicated. # This does not work! dd if=/dev/hdb | (pv -s `...
Created by Dr. Xi on December 05, 2009 20:12:16    Last update: December 05, 2009 20:46:45
It's quite easy for Perl to open a pipe and read from it: $file = "nospace.txt"; open(IN, "cat $file |") ... But the code breaks when the file name contains a space: # This does not work! $file = "yes space.txt"; ... On Windows, these don't work either: # This does not work! $file = "yes space.txt"; ... You need to use a technique called Safe Pipe Opens : $file = "yes space.txt"; $prog = "cat"; ...
Created by Dr. Xi on October 06, 2008 22:48:08    Last update: October 06, 2008 22:50:11
A first attempt would be to create an input file like this: userid password shell_command1 shell_... and feed the lines to the telnet client: cat telnet_input.txt | telnet remote_host #... However, you'll learn soon enough that it doesn't work. You get output like this: Trying 192.168.159.128... Connected to bash... What's happening? The telnet client depleted all input before the remote host had a chance to respond. Since there's no more input, the telnet client initiated to close the connection. Adding a delay between the commands makes it work: (echo userid sleep 10 echo password ... How much time to sleep between commands is just guesswork. You can use Expect to provide more control over the automated session: #!/usr/bin/expect # timeout script aft......