Browsing all articles in Linux
Mar
4

How to Remove ^M Character

There are a lot of other systems out there other than Linux, so if you have a file from, let’s say a DOS system, with extra ^M (caret M) characters at the end, you can correct it using vi. The tough part is, you will not be able to see these extra characters immediately, unless you encounter something like this:

$ ./check_summary.pl --help
-bash: ./check_summary.pl: /usr/bin/perl^M: bad interpreter: No such file or directory

(Note: check_summary is a Nagios plugin that I am currently testing.)

See the ^M character at the end? It is called the DOS line break. Unfortunately, Linux is not able to recognize these line breaks so you have to delete them. With vim. Yes, with vim, or with any editor you want, but in this post, I will show how to do it in vi.

First, open up your file where there is an extra ^M characters. While in command mode, type the following:

:%s/^V^M//g

The ^V is a CONTROL+V character and ^M is a CONTROL+M. When you type this, it will look like this:

:%s/^M//g

This command searches for ^M character (the CONTROL+V escapes a control character) the replaces it with null. After doing this, save and exit.

Another way to fix this is to use the dos2unix command like so:

$ dos2unix [file]

This might work, but I have not tried yet. Have you tried using dos2unix? Did it work? Let me know in the comments section.

Feb
27

Strict Standards: date() [function.date] Error

I was installing NagVis when I came across this weird message:

Strict Standards: date() [function.date]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘UTC’ for ‘GMT/0.0/no DST’ instead in /usr/local/nagios/nagvis/nagvis/includes/classes/objects/NagVisStatefulObject.php on line 360

It clearly says that I should check the timezone, which I did. But there’s nothing wrong with time or date. ntpd is running and it set the correct timezone so what could be wrong?

If you are reading this then probably you are seeing this error too. To fix this, open your php.ini using your favourite text editor (like vi) and add this line:

date.timezone=UTC

Take note that depending on how you installed php, it could be in /etc/php.ini (RedHat) or /etc/php5/apache2/php.ini (SLES) or if compiled, /usr/local/php5/php.ini.

You need to restart Apache for changes to take effect.

Jan
17

How to Copy Terminal Session into a File

Have you ever wondered how to copy the output of your terminal into a text file? Or maybe you teach Linux and you want to see what your students typed in and as well as the output? You think that running history is not enough? Then you need the script command.

Running script command

Open the man page of script command and you will see this:

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).

In a nutshell, it is history and tee all rolled into one. It will record everything you see on your screen, even the color. So if you typed in an invalid command, you will see the error in the log or if you run it correctly, you will have the output. But commands like top that refreshes the screen at an interval will most likely ruin the session or the log, so try to avoid similar commands.

To use it, just type the command script and it will begin recording the session. Once you are done, just type exit.

This is script in action:


rai@host1:~> script -a /tmp/script_test.log


Script started, file is /tmp/script_test.log
rai@host1:~> ls /home
R20 r200 R21 rai xx19
rai@host:~> thisnotacommandbutirunitanyway
bash: thisnotacommandbutirunitanyway: command not found
rai@host1:~> exit
Script done, file is /tmp/script_test.log
rai@host1:~> cat /tmp/script_test.log
Script started on Mon 17 Jan 2011 06:24:12 PM PHT
rai@lhost1:~> ls /home
R20 r200 R21 rai xx19
rai@host1:~> thisnotacommandbutirunitanyway
bash: thisnotacommandbutirunitanyway: command not found
rai@host1:~> exit

Script done on Mon 17 Jan 2011 06:24:54 PM PHT

The example above shows that script was started with -a option meaning it will append the output the specified file.

A better way to do this is to use it together with mkfifo command:

On Terminal 1 (Student’s terminal):

rai@host1:~> mkfifo /tmp/script_test.fifo
rai@host1:~> script -f /tmp/script_test.fifo

On Terminal 2 (Teacher’s terminal, same machine):

rai@host1:/tmp> cat /tmp/script_test.fifo

The above scenario will perform the following:
1) On the Student’s terminal, it will create an named pipe /tmp/script_test.fifo (man mkfifo) then run the script command with the -f option that ‘flushes’ out the output after each run. The Student’s terminal will look like it is not responding at this point, but don’t worry, it is perfectly normal.
2) On the Teacher’s terminal, the command cat will read the output file. Once you run the cat command, the session will be started.

Try the above steps and see how each screen behaves. Check also if doing the script command will create a populated output file.

Feb
1

Common Linux Configuration Files

Every user who switches from Windows to Linux has the fear of editing configuration files using the command line interface (CLI). If you are one of those people, then I am here to guide you through the most common configuration files found in a Linux system. Please note that to be able to edit these files, you need to have knowledge in file editors such as vim or pico.

/etc/profile
System wide environment variables for all users.

/etc/fstab
List of devices and their associated mount points. Edit this file to add cdroms, DOS partitions and floppy drives at startup.

/etc/motd
Message of the day broadcast to all users at login.

/etc/rc.d/rc.local
Bash script that is executed at the end of login process. Similar to autoexec.bat in DOS.

/etc/hostname
Contains full hostname including domain.

/etc/cron.*
There are 4 directories that automatically execute all scripts within the directory at intervals of hour, day, week or month.

/etc/hosts
A list of all know host names and IP addresses on the machine.

/etc/httpd/conf
Parameters for the Apache web server

/etc/inittab
Specifies the run level that the machine should boot into.

/etc/resolv.conf
Defines IP addresses of DNS servers.

Jan
31

Linux Shortcuts Every Newbie Should Know

Linux Shortcuts Every Newbie Should Know

One thing that Linux is not so popular of is that it has quite a few keyboard shortcuts that every Linux user should know. Here are a few examples of Linux shortcuts that will help anyone who uses Linux.

<Ctrl><Alt><F1>
Switch to the first text terminal. Under Linux you can have several (6 in standard setup) terminals opened at the same time.

<Ctrl><Alt><Fn> (n=1..6)
Switch to the nth text terminal.

tty
Print the name of the terminal in which you are typing this command.

<Ctrl><Alt><F7>
Switch to the first GUI terminal (if X-windows is running on this terminal).

<Ctrl><Alt><Fn> (n=7..12)
Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1). By default, nothing is running on terminals 8 to 12, but you can run another server there.

<Tab>
(In a text terminal) Autocomplete the command  if there is only one option, or else show all the available options.

<ArrowUp>
Scroll and edit the command history. Press <Enter> to execute.

<Shift><PgUp>
Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.

<Shift><PgDown>
Scroll terminal output down.

<Ctrl><Alt><+>
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file /etc/X11/XF86Config (the first resolution starts on default, the largest determines the size of the “virtual screen”):
Modes “1024×768″ “800×600″ “640×480″ “512×384″ “480×300″ “400×300″ “1152×864″

<Ctrl><Alt><->
(in X-windows) Change to the previous X-server resolution.

<Ctrl><Alt><BkSpc>
(in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally.

<Ctrl><Alt><Del>
Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. Don’t just press the “reset” button for shutdown!

<Ctrl>c
Kill the current process (mostly in the text mode for small applications).

<Ctrl>d
Log out from the current terminal.  See also the next command.

<Ctrl>d
Send [End-of-File] to the current process. Don’t press it twice else you also log out (see the previous command).

Powered by 1and1.comGlobat Webhosting Earn with Your BlogAdvertise @ PinoyTux

Search PinoyTux

Subscribe to Email Feeds

Enter Email Address:

Blog Lounge

Popular Posts

Recent Posts

Drop your Card Here

Recent Comments

Site Stats