Bo Wu's IT Lab

博闻精思 物我一体

Browsing Posts in Command Line

How to Unzip Multiple=

When you try:
unzip *.zip

You will get the following error:
caution: filename not matched

When you want to unzip file using wild card, you have two options as follows.

Option # 1 : unzip multiple files using single quote (short version)

Type the command as follows:
$ unzip ‘*.zip’

Note that *.zip word is put in between two single quote, so that shell will not recognize it as a wild card character.

Option # 2 : unzip multiple files using shell for loop (long version)

You can also use for loop as follows:
$ for z in *.zip; do unzip $z; done

terminal 10 UNIX Command Line Mistakes

Anyone who has never made a mistake has never tried anything new. — Albert Einstein.

Here are a few mistakes that I made while working at UNIX prompt. Some mistakes caused me a good amount of downtime. Most of these mistakes are from my early days as a UNIX admin.

userdel Command

The file /etc/deluser.conf was configured to remove the home directory (it was done by previous sys admin and it was my first day at work) and mail spool of the user to be removed. I just wanted to remove the user account and I end up deleting everything (note -r was activated via deluser.conf):

userdel foo

Rebooted Solaris Box

On Linux killall command kill processes by name (killall httpd). On Solaris it kill all active processes. As root I killed all process, this was our main Oracle db box:

killall process-name

Destroyed named.conf

I wanted to append a new zone to /var/named/chroot/etc/named.conf file., but end up running:

./mkzone example.com > /var/named/chroot/etc/named.conf

Destroyed Working Backups with Tar and Rsync (personal backups)

I had only one backup copy of my QT project and I just wanted to get a directory called functions. I end up deleting entire backup (note -c switch instead of -x):

cd /mnt/bacupusbharddisk
tar -zcvf project.tar.gz functions

I had no backup. Similarly I end up running rsync command and deleted all new files by overwriting files from backup set (now I’ve switched to rsnapshot)

rsync -av -delete /dest /src

Again, I had no backup.

Deleted Apache DocumentRoot

I had sym links for my web server docroot (/home/httpd/http was symlinked to /www). I forgot about symlink issue. To save disk space, I ran rm -rf on http directory. Luckily, I had full working backup set.

Accidentally Changed Hostname and Triggered False Alarm

Accidentally changed the current hostname (I wanted to see current hostname settings) for one of our cluster node. Within minutes I received an alert message on both mobile and email.

hostname foo.example.com

Public Network Interface Shutdown

I wanted to shutdown VPN interface eth0, but ended up shutting down eth1 while I was logged in via SSH:

ifconfig eth1 down

Firewall Lockdown

I made changes to sshd_config and changed the ssh port number from 22 to 1022, but failed to update firewall rules. After a quick kernel upgrade, I had rebooted the box. I had to call remote data center tech to reset firewall settings. (now I use firewall reset script to avoid lockdowns).

Typing UNIX Commands on Wrong Box

I wanted to shutdown my local Fedora desktop system, but I issued halt on remote server (I was logged into remote box via SSH):

halt
service httpd stop

Wrong CNAME DNS Entry

Created a wrong DNS CNAME entry in example.com zone file. The end result – a few visitors went to /dev/null:

echo 'foo  86400  IN CNAME lb0.example.com' >> example.com && rndc reload

Failed To Update Postfix RBL Configuration

In 2006 ORDB went out of operation. But, I failed to update my Postfix RBL settings. One day ORDB was re-activated and it was returning every IP address queried as being on its blacklist. The end result was a disaster.

Conclusion

All men make mistakes, but only wise men learn from their mistakes — Winston Churchill.

From all those mistakes I’ve learnt that:

  1. Backup = ( Full + Removable tapes (or media) + Offline + Offsite + Tested )
  2. The clear choice for preserving all data of UNIX file systems is dump, which is only tool that guaranties recovery under all conditions. (see Torture-testing Backup and Archive Programs paper).
  3. Never use rsync with single backup directory. Create a snapshots using rsync or rsnapshots.
  4. Use CVS to store configuration files.
  5. Wait and read command line again before hitting the dam [Enter] key.
  6. Use your well tested perl / shell scripts and open source configuration management software such as puppet, Cfengine or Chef to configure all servers. This also applies to day today jobs such as creating the users and so on.

Mistakes are the inevitable, so did you made any mistakes that have caused some sort of downtime? Please add them into the comments below.

FTP

No comments

ftp FTP

About FTP

FTP is short for File Transfer Protocol, this page contains additional information about the FTP command and help using that command in Unix and MS-DOS (Windows). See our FTP section in our dictionary for a complete definition on FTP.

Windows FTP

From the MS-DOS prompt or shell type in FTP, once typed in you will have access to the FTP command line. In this command line type:

open ftp.address.domain

Where address is the name of the server and the domain is the domain such as .COM, .NET… In addition, the IP address can be typed in, such as 255.255.255.0.

Once connected you will be asked for a username and password; if done successfully, you will have access to transfer files between computers.

Unix FTP

Unix FTP is used much like Windows; from a command prompt or shell, type in FTP, from FTP you should be able to log into a server, providing you have the proper access.

FTP Commands

Depending upon the version of FTP and the operating system being used, each of the below commands may or may not work. Generally typing -help or a ? will list the commands available to you.

Command   Information
!    Using this command you will have the capability of toggling back and forth between the operating system and ftp. Once back in the operating system generally typing exit will take you back to the FTP command line.
?    Access the Help screen.
abor    Abort Transfer
append    Append text to a local file.
ascii    Switch to ASCII transfer mode
bell    Turns bell mode on / off.
binary    Switches to binary transfer mode.
bye    Exits from FTP.
cd    Changes directory.
cdup    Change to parent directory on remote system
close    Exits from FTP.
cwd    Change working directory on remote system
dele    Delete file on remote system
delete    Deletes a file.
debug    Sets debugging on / off.
dir    Lists files if connected.

dir -C = Will list the files in wide format.
dir -1 = Lists the files in bare format in alphabetic order
dir -r = Lists directory in reverse alphabetic order.
dir -R = Lists all files in current directory and sub directories.
dir -S = Lists files in bare format in alphabetic order.
disconnect    Exits from FTP.
get    Get file from the computer connected to.
glob    Sets globbing on / off.
hash    Sets hash mark printing on / off
help    Access the Help screen and displays information about command if command typed after help.
lcd    Displays local directory or if path typed after lcd will change local directory.
list    Send a list of file names in the current directory on the remote system on the data connection.
literal    Sends command line
ls    Lists files if connected.
mdelete    Multiple delete
mdir    Lists contents of multiple remote directories
mget    Get multiple files
mkd    Make directory.
mkdir    Make directory.
mls    Lists contents of multiple remote directories.
mode    Specifies the transfer mode. Available parameters are generally S, B or C.
mput    Sent multiple files
nlst    Send a full directory listing of the current directory on the remote system on the data connection.
open    Opens address.
pass    Supplies a user password.
port    Specify the client port number.
prompt    Enables/disables prompt.
put    Send one file
pwd    Print working directory
quit    Exits from FTP.
quote    Send arbitrary ftp command
recv    Receive file
retr    Get file from remote system.
remotehelp      Get help from remote server
rename    Renames a file
rmdir    Removes a directory
send    Send single file
status    Shows status of currently enabled / disabled options
trace    Toggles packet tracing
type    Set file transfer type
user    Send new user information
verbose    Sets verbose on / off.

TECHNICAL SUPPORT

How do I send and receive files once connected in MS-DOS FTP?

To get files from the server and place them in your current working directory, on the machine you are working, type:

get myfile.htm

Where myfile.htm is the name of the file you wish to get from the computer connected to.

To send a file from your computer to the computer you are connected to (providing you have proper rights and the file exists in the current working directory), type:

send myfile.htm

Where myfile.htm is the name of the file that exists in the current directory; if you cannot recall the name of the file, use the ! command to temporally get back to a MS-DOS prompt; once you have located the file name, type exit to get back to the location you left in FTP.

In MS-DOS FTP I am only able to send files in the directory that I typed FTP in.

Set the LCD, for example, if you want to send files that are in the C:\Windows directory, type:

LCD c:\windows

How do I download multiple files from an FTP server?

Use the mget command, which is short for multiple get. Using the mget command you can get multiple files by using wildcards. For example, ” mget *.* ” would get all files in the current directory.

By default, prompting would be enabled; if you wish to get all files without being prompted, use the “prompt” command to disable/enable prompting.

When attempting to connect to an FTP address, receiving  “10061″ error

This error is caused when the server is refusing the connection.

Attempt to connect to an alternate FTP address.

If you are able to connect to other FTP addresses, it is likely the site generating the error 10061 is refusing to accept your connection because of security privileges or because it is not an FTP server.

If you are unable to connect to any address, it is likely an issue with the network or computer configuration.

1. Ensure that the network configuration settings are properly setup as well as FTP rights.
2. Verify that the firewall is properly setup to accept FTP access.

How to create a Windows FTP script

Create a text document with commands used when in FTP.  Below is an example of what such a script may look like:

open ftp.domain.com
username
password
cd public_html
dir
get file.txt
bye

The above script will log into the ftp site ftp.domain.com. Once connected, it will enter the username and then the password (substitute username for your username and password for your password). Once logged in, the script then goes into the public_html directory, gets a directory listing and then uses the get command to get the file called file.txt. Once the file is received, it logs off using the bye command.

Once the script file has been created, for example, if it was called script.txt, to execute this script with ftp you would type:

ftp -s:script.txt

If Windows FTP does not offer enough scripting options for you you may also want to consider WinSCP.

PDF How to concatenate multiple PDF files into one?

Make sure the gs (Ghostscript) is installed, and type following command:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished a.pdf b.pdf