Colours in nano

I am writing most of my bash script with nano editor. If one want to get colours in nano, on can do:

[bash]
locate *.nanorc
[/bash]

which will give a list of what is available on your system:
/usr/share/nano/html.nanorc
/usr/share/nano/java.nanorc
/usr/share/nano/man.nanorc
/usr/share/nano/mutt.nanorc
/usr/share/nano/nanorc.nanorc
/usr/share/nano/perl.nanorc
/usr/share/nano/python.nanorc
/usr/share/nano/ruby.nanorc
/usr/share/nano/sh.nanorc

Now, you can do:

[bash]
nano -w ~/.nanorc
[/bash]

and add your prefered styling.

Since I am happy with bash, I would add:
include /usr/share/nano/sh.nanorc
to my file.
Read more here:
http://askubuntu.com/questions/90013/how-do-i-enable-syntax-highlighting-in-nano

See blow how it looks like on my computer:

colours in nano

The text below is what I wrote a couple of years ago, but I keep just in case.

 

Some might remember the editor ‘pico’, today most people know it as ‘nano’.

Have you missed sometime to have colour highlighting when editing bash and php scripts with nano? Here are two interesting projects:

https://github.com/craigbarnes/nanorc

and

https://github.com/alekstorm/nanorc

nano editor with colours

sed

sed is a linux command that can replace characters and words in a file very easy!

Syntax:

sed -i 's/word/newword/g' file.txt

It means:

replace all “word” with “newword” in the file called “file.txt”. Be aware! The option -i means that you will manipulate the file file.txt on-the-fly!
If you are not sure, skip the -i option.

Use ‘mutt’ to send email with attachment

The unix ‘mutt’ command can be used to send an email with attachment:

mutt -s "Test message" name@something -a files.tar < message.txt

where files.tar is the attached file, and message.txt is the file containing the message.

Subject to the email is added with the -s option. In this case:
-s “Test message”

name@something is the receiver email address

You can also do this:

echo "Message text" | mutt -s "Subject text" name@something -a files.tar

Reference: http://www.cyberciti.biz/tips/sending-mail-with-attachment.html

Why would you like to use a unix command to send an email with an attachment?
The answer is that in the case you want to automate some process, let us say, you would like to pack together some important files, and send them every Sunday to a certain person. It could be statistical data, for instance, and the person would like to have a report each Sunday so to read them on Monday before lunch.
You could then make a simple bash script that uses ‘tar’ to collect the files into a single tar-file. Then call on the unix ‘mutt’ command, and send the message together with the important tar-file. All can be automated by calling this bash script from cron (unix job scheduler)

tar

Create a tar file of files located in a folder:
tar -cvf filname.tar foldername/

where:
c = create
v = verbose
f = file

filname.tar = the created file

———-
To show the content of a tar’ed file:
tar -tvf filname.tar

———-

extract a file with tar:
tar -xvf filname.tar

where

x = extract
v = verbose
f = file

ldapsearch users and places that contains æ, ø and å

We needed to collect “Place” information per user from our LDAP server.
The problem was that the description of the “Place” came out strangely encoded whenever it contained one of the norwegian characters æ,ø or å.

The ldap command:

ldapsearch -x -H ldap://ourldapserver.uib.no x121Address=XXXXXX

where XXXXXX is the “place” code, gave a place description that looked like this:

description:: SW5zdGl0dXR0IGZvciBmaWxvc29maSBvZyBmw7hyc3Rlc2VtZXN0ZXJzdHVkaWVy

where the real name of “Place” could be something like: “Institutt for .. and then a word with æ, ø or å”

The solution was to use ldapsearch as follows:
ldapsearch -x -z 1 -t departmentNumber=XXXXXX ou

where XXXXXX is the University of Bergen “placecode” for a “Place”. For instance the number 567123 could be the place code for our IT department.
-z 1 reduces the list of hits to one (1), and ou specifies the “Place” description.

The list of users was already collected in a text file: people.txt on the form:

username1
username2

The bash script that solved the issue for me was:

[code lang=”bash”]

#!/bin/bash
# People collected with:
# ls -al /www/folk/ |awk {‘print $9’}|grep -v unwanted_line|sort > people.txt

PEOPLE=`cat people.txt`

for USERNAME in $PEOPLE; do
PLACECODE=`ldapsearch -x -H ldap://ourldapserver.uib.no uid=$USERNAME | grep departmentNumber | awk {‘print $2’}`

if [ ! -z $PLACECODE ]; then

# Some times name of place is written to screen, other times to a file under /tmp
OUINFO=`ldapsearch -x -z 1 -t departmentNumber=$PLACECODE ou | grep ‘ou:’`

if [ `echo $OUINFO | grep ‘file:’ | wc -l` -eq 0 ];then
PLACE=`echo $OUINFO | sed -e s/"ou:\ "//g`
else
THEFILE=`echo $OUINFO | grep ‘file:’ | sed -e s/".*file:\/\/"//g`
PLACE=`cat $THEFILE`

#echo "The file is: " $THEFILE
#echo "and the place is: " $PLACE

fi
fi
echo $USERNAME, $PLACE
done

[/code]