Friday, December 16, 2011

Evolution of shells in Linux

Pointing and clicking is fine for most day-to-day computing tasks, but to really take advantage of the strengths of Linux over other environments, you eventually need to crack the shell and enter the command line. Lots of command shells are available, from Bash and Korn to C shell and various exotic and strange shells. Learn which shell is right for you.

read more...

Wednesday, December 14, 2011

Manage System Startup and Boot Processes on Linux with Upstart

Want to start, stop, and manage services on your Linux box? Then you need to familiarize yourself with Upstart and take control of your startup and boot processes on Linux.
When Linux boots up, the first process that runs is called init. From there, init takes the task of starting up system processes. But which init? Turns out, there are several flavors of init, and it depends on which Linux distribution you're using and how modern the release is. Let's take a look at some of the backstory.

BSD, System V, Upstart and systemd init, Oh My...

You might think that the way that the system starts would be fairly well-agreed upon between Linux distributions. Unfortunately, that's not been the case and may not be the case for some time.

Linux isn't directly derived from UNIX, but it takes a lot of ideas from UNIX, including the way that the system starts. Some Linux distros, most notably Slackware, used the BSD-style init. Slackware (and its derivatives) is the lone holdout for this style these days, and it includes a System V init compatibility workaround so that applications that expect to support System V init scripts can install them normally.
System V (from UNIX System V), the precursor to was the standard for most Linux distros for many years. Distros using SysV init would have several directories under /etc such as rc0.d, rc1.d, through rc6.d for each runlevel — though many of the runlevels are not really implemented.
What's a runlevel, you ask? Essentially this is the grouping of services that are run by init. For example, runlevel 0 is "halt," runlevel 1 or S are the "single user mode," and runlevel 6 is reboot. On Fedora/Red Hat systems, runlevel 3 is a full set of services to run a multiuser system (networking, etc.), and runlevel 5 includes multiuser services and X11 with the display manager. You'll notice I didn't mention 2 or 4, because those runlevels are rarely used and runlevel 4 isn't even defined by default.
Note that you can switch between runlevels using the telinit command, like so: telinit 3 would switch to runlevel 3, and telinit 6 would tell the system to reboot. Note that you would usually want to just use reboot instead to reboot, but telinit 6 would also work.
Under each of the directories, you'd have a set of symbolic links that point back to scripts that include startup and shutdown directives for services like Apache and the SSH daemon. Each link has a name like KNNsshd or SNNcups, where the NN determines the order in which services are killed (K) or started (S). This became tricky with laptops and mobile systems, because the state of a computer might determine the order in which services should be started. See the rationale for Upstart by Scott James Remnant for more detail — but the short of it is that the SysV style init that served Linux well for many years became rather fragile and creaky when Linux adapted to use as a notebook OS as much as a server OS.
So now we have, or had, Upstart as the emerging standard. For now, Upstart is the sort-of standard for several distros. Upstart is used by Ubuntu, current Fedora releases, and openSUSE 11.3 includes it as an optional package. But the Fedora folks are working on a replacement for Upstart called systemd, which is a "system and session manager" that is meant to be a "drop-in replacement for sysvinit." There's a very detailed discussion of the rationale behind systemd by Lennart Poettering that is an interesting read if you're interested in the deep details. So at some point, you'll need to know Upstart or systemd, or both if you are managing systems using Upstart and systemd.
For now, we're going to look at Upstart.

Managing Startup Services

Now, when we're talking about startup services, I mean the system-wide services like SSH and Apache, not the applications started up by your desktop. That's a whole different kettle of fish, and depends on the desktop that you're using. For example, if you're running a recent Linux distro with GNOME, you'll look at System -> Preferences -> Startup Applications.
For applications managed with Upstart, you'll first want to look at the initctl command. This allows you to work with Upstart's init daemon. Naturally, you're going to need to use sudo to run initctl or be logged in as root.
To see what's running on your system, use initctl list. You'll see something like this:

alsa-mixer-save stop/waiting
avahi-daemon start/running, process 690
mountall-net stop/waiting
rc stop/waiting
rsyslog start/running, process 482
screen-cleanup stop/waiting
tty4 start/running, process 859
udev start/running, process 334
upstart-udev-bridge start/running, process 304
ureadahead-other stop/waiting
 
 
This is from a system running Ubuntu 10.10, you'll see a different list of jobs on Fedora 14 or another distro. The first field is the name of the job — like rsyslog. The second field is the "goal" of the job, followed by the state of the job.
To stop a job that's running, use initctl stop job. To start a job, run initctl start job. You can also request status of jobs with initctl status job. Finally you can restart or reload jobs with the restart and reload commands. What's the difference between restarting and reloading? Restarting does what it says on the tin — stops the job and then restarts it. The reload command sends the SIGHUP signal to the job, which can be used to tell a daemon to re-read its configuration.
For jobs that are managed by Upstart, you can edit their configuration file under /etc/init. They will have a few lines that describe which runlevels to start/stop on like so:


start on runlevel [2345]
stop on runlevel [!2345] 
 
Change the runlevels as necesary.
If you're using a desktop system, you'll want to install the Boot-up Manager — a GUI tool for handling runlevel configuration. The package is bum, and it will let you manage jobs and configure services by runlevel. It's simple to use, and shouldn't require a lot of guidance.
Note that Fedora uses Upstart in SysV compatibility mode, which means that a lot of jobs on Fedora are not managed with native Upstart scripts. For those jobs you'll want to use the service command.
To see the status of all jobs on Fedora using service run:
service --status-all
This will show which jobs are stopped, running, and in a few instances much more information. For example, iptables will spit out its entire set of policies that are running at the moment.
To manage a job with service use service servicename command. The servicename is the name of the configuration script under /etc/init.d. For example, to start and stop the openSSH daemon, you'll use service sshd start or service sshd stop.
If you want to tweak the services by runlevel, use the chkconfig command. You'd use something like chkconfig --level 35 cups on to tell chkconfig to make sure that cups is started in runlevels 3 and 5.
What if you want to add a service or modify the scripts for existing services? One quick and dirty way is to use /etc/rc.local. The script should be run during any startup or change of runlevel. Another way is to modify the scripts under /etc/init.d (for SysV compatibility) or /etc/init (native Upstart scripts) or write your own for a new service.
Typically, this is unnecessary — almost any service that you'll be using should have init scripts pre-written. Writing an init script, whether for Upstart or for SysV, is a bit outside the scope of this tutorial.
Since many users are going to be transitioning to systemd, we'll take a longer look at managing jobs with systemd when Fedora 15 comes out.
Most of the time, your interaction with managing services should be minimal unless you're working with Linux as a full-time admin. If you are doing system administration, or planning to, you should already be familiar with the init system that your distros are using. If not, now's a good time to learn. If you're a desktop Linux user, you probably won't be managing services very often, but it's a good to know the basics that we've covered here in case you need to do any troubleshooting or just want to fine-tune your system.



Ref:  https://www.linux.com/learn/tutorials/404619-manage-system-startup-and-boot-processes-on-linux-with-upstart

https://www.linux.com/learn/tutorials/524577

 

Monday, October 31, 2011

Vim Tips

1.I always wished that as a programmer , I should not waste my time in
 writing the trivial stuff, the one I require every time I sit to write the
 program. For example, while writing any C-program, we have the general
 format of #include<...> & then main() {  ... return 0 ; }
 What if every time I start writing the program, this format is ready for me
 ?? Well thats possible, atleast with "vim".

Create the standard format of the file you want , lets say at <~/format> is
 the path.

Now start vim : vim ,& then type , in command-mode ---> :r
 ~/format ,thats all , whatever is in the file <~/format> will be simply
 pasted .

I have created the file : <~/lic.c> , it contains the GNU GPL disclaimer.
 Now after I finish writing the program , I just have to say ( in command
 mode ) --> :r ~/lic.c , thats all, the license-terms get pasted .
 It looks like this :
 /* ########################################################################
  *
  *LAST UPDATED :

 *Copyright (C) 2011 Lokesh Walase
  *
  * Released under GNU General Public License v2.0+ .
  * FOR DETAILED LICENSE, SEE THE END OF THIS PROGRAM.
  *
  *########################################################################
  */

/*####################################################################################################################
 *
 *This program is free software; you can redistribute it and/or modify
 *it under the terms of the GNU General Public License as published by
 *the Free Software Foundation; either version 2 of the License, or
 *(at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 * Visit
 *
 *To  receive a copy of the GNU General Public License
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *Boston, MA  02110-1301  USA

*The GNU General Public License does not permit incorporating this program
 *into proprietary programs.
 *
 *
 ########################################################################################################################
 */

2.As you might have noticed , the <~/lic.c> has the field --> LAST UPDATED
 :  , now to put the date & time here , go to that line, & in command mode
 ---> :r !date .

3.Well, if that didnt really raise your eyebrows, here's somemore . What is
 the best thing of the "terminal" ?? Yes, it "auto-completes" the commands
 by '\t' key. Now what if the same feature of "auto-completion" is present
 everywhere & not only in the "terminal" ?? Well thats possible, (again)
 atleast with "vim" .

Create a new <.vimrc> file in your home-folder . Say : vim .vimrc , at your
 home-folder & then copy paste this code( I found it on net ) :

        *function! Tab_Or_Complete()
          if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
                  return "\"
             else
                         return "\"
                endif
         endfunction
          :inoremap =Tab_Or_Complete()
          :set dictionary="/usr/dict/words"
 *
 Pls be sure of the indentation ,everything has to be strictly indented . I
 dont know what exactly it is doing .
 Now vim will "auto-complete" any words you type , press '\t' for the same .
 Its indeed cool ........proud to be a "vimmer" !! ;)

4.Now whats next ?? Well, enough of vim. Recently I came to know of the
 command that can convert .pdf files to text-files, post-script files ,
 html-files & many more. Just type in the terminal & then you press
 '\t' twice to see all the options .
 Reading man pages is boring , so u may convert a lengthy man-page to a html
 file & get a nice look & feel to read it , I did it for "info flex" .
 Type : info flex > flex.odt . Now open flex.odt & get its pdf format , &
 then use command --> pdftohtml flex.pdf flex.html


Ref : http://groups.google.com/group/cofsug/browse_thread/thread/d5edacf343486d03?hl=en-GB



 

Wednesday, October 19, 2011

How do I make changes to a package and capture them using ltib

1. Unpack the sources and apply all current patches:

./ltib -m prep -p u-boot
 
2. Edit/add files under rpm/BUILD/package/
3. Build the package with your changes:

./ltib -m scbuild -p u-boot
 

4. Once the package builds successfully, check the install phase:


./ltib -m scinstall -p u-boot
 
5. Test your package before committing the changes:
./ltib -m scdeploy -p u-boot
 
6. Repeat steps 2 -> 5 until you are satisfied with your results. 
 
Ref:  http://ltib.org/documentation-LtibFaq


Friday, September 16, 2011

Programming tips

Why not to use gets() in Linux ?
Ans:  http://c.ittoolbox.com/groups/technical-functional/c-l/store-character-string-containing-spaces-using-structure-4414903
-----------------------------------------------------------------

Command to change vdi's uuid.
$ VBoxManage internalcommands setvdiuuid disk.vdi
-----------------------------------------------------------------


LDD3 examples

-----------------------------------------------------------------

C Programming

http://codingrelic.geekhold.com/search/label/C%20Programming


Monday, July 25, 2011

ssh login problem

Problem: When I try to connect target board using ssh, it gives me error of 'password has expired'. The log is given below.

-------------------------------------------------------------------------------

$  ssh root@192.168.1.142
root@192.168.1.142's password:
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for root
New password:
Bad password: too short
Retype password:
Password for root changed by root
Connection to 192.168.1.142 closed.
---------------------------------------------------------------------------------

Soln: change the entry in shadow file,
old entry: root:$1$bmWHS8dA$cWZORf5md8ecQbEvL.Ule.:0:0:99999:7:::
new entry: root:$1$bmWHS8dA$cWZORf5md8ecQbEvL.Ule.:11851:0:99999:7:::

The problem is in shadow file, in this 'days since last password changed' field is set 0, so change modify it.


Ref: http://lists.busybox.net/pipermail/buildroot/2011-March/042165.html

Friday, May 20, 2011

Interview

ioctl

Q] Why ioctl() operation is removed form Linux Kernel 2.6.36?
Ans: When ioctl was executed, it took the Big Kernel Lock (BKL), so nothing else could execute at the same time. This is very bad on a multiprocessor machine, so there was a big effort to get rid of the BKL. First, unlocked_ioctl was introduced. It lets each driver writer choose what lock to use instead. This can be difficult, so there was a period of transition during which old drivers still worked (using ioctl) but new drivers could use the improved interface (unlocked_ioctl). Eventually all drivers were converted and ioctl could be removed.
compat_ioctl is actually unrelated, even though it was added at the same time. Its purpose is to allow 32-bit userland programs to make ioctl calls on a 64-bit kernel. The meaning of the last argument to ioctl depends on the driver, so there is no way to do a driver-independent conversion

Friday, January 14, 2011

मराठी भाषेची ताकद

खालील  लेखात, प्रत्येक शब्द 'आणि ' पासून सुरु करुन येवढा मोठा परिच्छेद लिहिला आहे.

 
------------------------------------------------ ---------------------------

केव्हातरी कोल्हापूरच्या कर्तव्यतत्पर केळकर काकांबद्दल काकांच्याच कचेरीतल्या केशवने काकूंसमोर कागाळी केली. काकू कावल्या. काकूंनी कपाटातून कात्री काढून काकांच्या कामाचे कोरे करकरीत कागद कचाकचा कापले. काकांचे कापलेले कागद केशवानेच कचऱ्यात कोंबून काकांच्याच किचनमध्ये 'कजरारे-कजरारेकवितेवर कोळीनृत्य केले.
काकूंनी कागद कापल्याचे कळताच काका कळवळले. काकांनीही कमालच केली. काकांनी काकूंचे काळे कुळकुळीत केस कात्रीने कराकरा कापले. काका काय करताहेत काकूंना कळेनाच! काकूंनी कर्कश्श किंचाळून कलकलाट केला.
काका काकूंची कसली काळजी करणार! काकांना कामाची काळजी. काकूंच्या कर्णकर्कश्श कोलाहलातहीकेशवाने कचऱ्यात कोंबलेले कागदाचे कपटेन कपटे काढून काकांनी कचेरीकडे कूच केले.
कचेरीच्या कामासाठी काकांनी कंबर कसली. कागदाच्या कापलेल्या कपट्यांचे काकांनी 'कोलाज'
करून कामकाज कार्यान्वयित केले. केशवाचे कारनामे कळताच काकांनी काट्यानेच काटा काढला.
काकांनी केशवालाच कोलाजचे काम करण्यासाठी कुथवला. कपटी केशवने काकांवरच कामचुकारपणाचा
कांगावा करून कामाचा कंटाळा केला. काकांनी कठोरपणे केशवाला कामावरून काढले. कासावीस काकूंनी कालच्या कडू कारल्याची कोशिंबीर कटाप करून काकांसाठी कच्च्या कैरीचे कोय काढून कालवण केले. काकांनीही करुणेने काकूंचे कृत्रिम केस कुरवाळले. केळकरांच्या कोकणस्थ कुटुंबात कर्तव्यापुढे कर्मकांड केव्हाही कनिष्ठच. कर्तव्यदक्ष काकांच्या कार्यकाळात कचेरीने कर्मरूपी किल्ल्याचे कीर्तिशिखर काबीज केले.
कामावरून काढलेल्या केशवाने कितीतरी काबाडकष्ट काढल्यावर कोल्हापूरच्या कॉम्रेड कणेकर
कॉलेजने केशवाला कबड्डीचा कर्णधार केला. क्रिडापटू केशवाने कबड्डीतच करियर केले. कालच्या  कागाळीखोर केशवाला काळानेच केला 'कबड्डीतल्या किचकट कसरतींचा कर्ता'!
कथासार
-
क्रियेविण करिता कथनकिंवा कोरडेची कीर्तन,
कितीक किताब कष्टाविणकाय कामाचे
 

------------------------------------------------ ---------------------------------

परवा पुराण-प्रसिद्ध पखवाज पंडित पुरोहित पंतांची पिवळी पगडी पुरंदरच्या पंधराशेव्या पायरीवरून पुण्यात पर्वतीच्या पाचव्या पायरीपाशी पर्णकुटीपासून पंधरा पावलांवर पहुडलेल्या पंकजच्या पोटावर पटकन पडली. पगडी पडलेली पाहताच पंत पुरंदरच्या पायथ्याशी पोलिसठाण्यात पळाले. पुरंदरच्या पोलिसांनी पंतांना पुण्याच्या पोलिसांकडे पाठवले.

पंत पुण्यात पोहोचताच पोलिसांवर पेटले. पंत पेटल्यामुळे पोलिस पटकन पर्वतीकडे पळाले. पांढर्‍या पोषाखातल्या पोलिसांना पाहून पंकज पर्वतीच्या पलिकडे पळाला. पोलिसांनी पंकजचा पिच्छा  पुरवला.

पळता पळता पंकज पाण्याच्या पाँडमध्ये पडला. पंतांनीच पाण्यात पोहून पंकजला पकडले. पिवळी
पगडी पण पकडली. पोलिसांनी पंकजला पोलिसठाण्याकडे पिटाळले. पकडणारा पोलिस पदपथावर
पाय पसरून पडला. पोलिस पडलेला पाहून पंकज पाठीवर पांघरूण पांघरून पळाला.

पंतांनी पुरंदरला पोहोचताच पगडीत पंकजचे पैशांचे पाकिट पाहिले. पाकिटातले पुष्कळ पैसे पंतांनी
पनवेलला पुत्राला पोस्टाने पाठवले. पंतांच्या पाजी पुत्राने पैशांच्या प्राप्तीतून पोटात पंजाबी पदार्थ पचवले.

पंतांना परमेश्वरच पावला!
पंकजला पकडण्यासाठी पंतांसोबत पुण्यात पोहोचलेली पंतांची पोरगी प्राची पंकजला पहिल्यांदा पाहताच पंकजच्या प्रेमात पडली. प्राचीने पंकज,पोलिसांची पकडा पकडी पाहिली. पंकजचा पदपथावरून पोबाराही पाहिला. पानशेतच्या पुराच्या पाण्यामुळे पुनर्वसित पंकज परत पर्णकुटीत पोहोचला.

पित्यासमवेत प्राची पुरंदरला परतलीपण पंतांनी पंकजच्या पाकिटातल्या पैशांबाबत पंक्ति-प्रपंच पाळला. पुष्कळ पैसे पुत्राला पाठवले. पंतांच्या पुन्हा पुन्हा पिडणार्‍या पुराणांच्या पोपटपंचीमुळे प्राची पेटली.

पंकजच्या प्रेमाखातर प्राची पुण्यास परतली. प्राचीनेच पंकजवरच्या पोलिसांच्या पंचनाम्याला  पाने पुसली. पंकजला पहायला प्राची परत पर्णकुटीपाशी पोहोचली. पण पर्णकुटीत पहुडलेल्या पंकजचे पाय पळून पळून पांढरे पडलेले! प्राचीने पंकजच्या पायावर पिवळे पुरळही पाहिले.

पंकजची परिस्थिती पाहून प्राण पिळवटलेल्या प्राचीने पदर पाण्यात पिळून पंकजचे पाय पुसले. प्राचीचा प्रथमोपचार पाहून पंकजला पोरगी पसंत पडली. पंकजने प्राचीला पर्णकुटीतच पटवले. पर्णकुटीतील प्रेम-प्रकरण पाहून पर्णकुटीच्या पायर्‍यांवर पत्ते पिसणारी पोरे पूर्व-पश्चिमेला पांगली. प्राचीने पंकजचे पा़किट पैशांविनाच परतवले. परंतू प्रेमात पारंगत पंकजने प्राचीस पाच पाप्या परतवल्या.

पंतांना परमेश्वर पावलापण पंकजला पंतांची पायाळू पोर पावली.