Converting dos to unix ascii files

There is just nothing in this world that is universal and that even includes straight up text files. When carriage returns are stored in windows they are stored as Carriage Return & Line Feed, however, in unix they are stoed as just Carriage Return.

So when you ftp a file from windows to unix sometimes you will see ^M characters at the end of each line. This is because the files has been transferred as a binary file versus an ascii file. Most ftp (sftp, ftps, etc..) programs will convert the carriage returns correctly if the file is set to transfer in ascii mode based on the operating system it is going to.

However, if by chance you end up with a “dos” based file on your unix system and you want to convert it. A quick simple trick is to use the vi editor using the the :set ff command.

Simply open the text file in the vi editor, and type
:set ff=unix

This will change the file format from dos to unix based and the carriage return problem should be solved!

Linux: Remove Files older then x days

The other night I had to cleanup a mess in a couple of directories and doing it by date seemed to be the easiest way. I found this command and it worked like a charm:

find /path/to/files* -mtime +5 -exec rm {} \;

Basically use the find command to the files in question, the -mtime function in this example will find files older then 5 days, the last part executes the remove command on file it finds.

Note: Before running this command with the remove code, just run the find part of the command to validate that the files being found are the ones you want to remove (Measure twice cut once!).

PGP/GPG on Linux

Linux is a great platform that has many advantages over a windows based platform, and one of those advantages is PGP (Pretty Good Privacy) available on a base install. In 1991 Phil Zimmermann created the first version of PGP encryption which allows for cryptographic privacy and authentication for data communication. It is widely used for securing email, but can be used to secure texts, files, directories, hard drives, and is now being used to encrypt entire computer systems.

To use PGP, you need to create or import a certificate into the keystore. The keys can be in DSA or RSA formats and have lengths of 1024 to 4096 bits on most systems. The certificates can also be set to never expire or be set to expire within a certain timeframe.

To List Keys in the Keystore:
pgp –list-keys

To Generate a new key:
gpg –gen-key

To Import an existing key:
gpg –import ~/keyfilename.gpg

To Import an existing key secret key:
gpg –allow-secret-key-import –import ~/secretkeyfilename.gpg

When you need to export the data, you will need to remember that there is two parts to the key, the public key, and the secret key. When a client wants to encrypt data for you they will require the public key.

To Export an existing key and secret key:
gpg –output keyfilename_public.gpg –armor –export keyname
gpg –output keyfilename_secret.gpg –armor –export-secret-key keyname

To Encrypt/Decrypt a file, remember the passphrase used, if forgotten your data will remain encrypted forever.

To Encrypt a file:
gpg -c filenametoencrypt (you will be asked for the passphrase to encrypt with).
Non-Interactive:
gpg –yes –passphrase={YourPassPhrase} -c filenametoencrypt

To Decrypt a file:
gpg filenametodecrypt (you will be asked for the passphrase used to encrypt with).
Non-Interactive:
gpg –yes –passphrase={YourPassPhrase} filenametodecrypt

PSUNX Fails To Print – Error “sh: lp: command not found”

This error is caused by the process scheduler (PSUNX) not being able to execute the “lp” program. Typically it is located in the /usr/bin directory. The easiest solution is to simply add this path to the addtopath variable in the process scheduler configuration setup. Typically the cblbin is already there so to append another path simply add it with a “:” colon separator.

AddToPath=/usr/bin:%PS_HOME%/cblbin

Another helpful tip is to make sure the print queues are setup which can be done by entering:

lpstat -t

Unix SCP – Remote Copy

The SCP command in unix is extremely useful for move files/directories from one server to another. If you log into the machine you want to transfer the files to and navigate to the directory where you want the file or directory, you can issue the following command:

To move a file: scp username@remoteserver:/home/username/example .

To move a directory: scp -r username@remoteserver:/home/username/exampledirectory .

The -r flag is to move all files/directories within the example directory. username is the remote servers user name, this can be eliminated if you want to login with the same user as you are currently logged in to the local machine with. remoteserver is the server that houses the file(s)/directory(s) you want to copy, and the “.” signifies to copy to the current location.