Tuesday, February 28, 2012

sed replace word / string syntax

sed replace word / string syntax

The syntax is as follows:
sed -i 's/old-word/new-word/g' *.txt
GNU sed command can edit files in place (makes backup if extension supplied) using the -i option. If you are using an old UNIX sed command version try the following syntax:

Monday, February 27, 2012

Make a Python script executable

Make a Python script executable on Unix?

You need to do two things: the script file’s mode must be executable and the first line must begin with #! followed by the path of the Python interpreter.
The first is done by executing “chmod +x scriptfile” or perhaps “chmod 755 scriptfile.
$ chmod +x myscript.py
The second can be done in a number of ways. The most straightforward way is to put
#!/usr/local/bin/python
as the very first line of your file, using the pathname for where the Python interpreter is installed on your platform.
If you would like the script to be independent of where the Python interpreter lives, you can use the “env” program. Almost all Unix variants support the following, assuming the python interpreter is in a directory on the user’s $PATH:
#! /usr/bin/env python
Don’t do this for CGI scripts. The $PATH variable for CGI scripts is often very minimal, so you need to use the actual absolute pathname of the interpreter.
Occasionally, a user’s environment is so full that the /usr/bin/env program fails; or there’s no env program at all. In that case, you can try the following hack (due to Alex Rezinsky):
#! /bin/sh
""":"
exec python $0 ${1+"$@"}
"""
The minor disadvantage is that this defines the script’s __doc__ string. However, you can fix that by adding
__doc__ = """...Whatever..."""

Monday, February 20, 2012

Putty ssh no wait before entering password

Open up a terminal window and edit the OpenSSH config file.
sudo vi /etc/ssh/sshd_config
At the end, paste this in:
# Fix slow login times
UseDNS no
Save and exit.
Now restart your OpenSSH daemon. You can do it while connected via SSH.
sudo /etc/init.d/ssh restart
That's it! It should now connect almost immediately.