Linux « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ Linux ’

Linux trick to get your user back to sudo access while you lost your Admin password and you are with no sudo prevailages.

Posted by Anuj Aneja on February 27th, 2011

I was trying to create new user on my machine but some how i create a new user but  i commited a mistake. That is  while making a new accout i forget to make it acive by giving password. And then i make this new account as Administrator and make my old account as Desktop User. Now the old_account can’t run ’sudo’ command in and i don’t have access to my admin account.Everytime while running a sudo command it give me the error as shown below:

old_user~$sudo -s

your account is not in sudoers list So this event will be reported.

And further in Ubuntu you have root account but it not by default active in there you  can switch to the root by typing:

old_user$su -
or
old_user$sudo -s

But will ask for root password which is not activated yet.

In this situtation i found a solution which can be done by editing sudoers list or group list file stored in /etc/sudoers ,/etc/group but to edit you require root access or sudo access. Which i lost it. Now to come out safe from this fishy situation take the following step:

1. Boot the system with any  Ubuntu live cd login as ubuntu now.
2.The password for Ubuntu user is blank and it is also added to sudoers list so now you can run sudo command:

ubuntu~$sudo -s
root~$

You are logged in as root.
3. Now type the following command in order:

root~$cd  /media/(some long name of you actual installation  folder)/etc/
root-.......etc/~$chmod 777 group
root-.......etc/~$vi group

Now i put the old_username in in front of sudo option like :

sudo:x:27:old_username

And save this file.

Now the old_user can run sudo command :)
I restarted my system and run the following commands

old_user~$sudo -s
enter password of old user:
root~$adduser old_user admin

Now old_user become the part of the admin group can perform any sudo,and admin opearation.Hurray !:)
The comment and any suggestion of doing this in a better way are always welcomed.
It helps me hope this helps you cheers! :)
Thanks
Anuj Aneja
Inelligrape Software

  • Share/Bookmark
Posted in Grails

Mysql Dump multipurpose script.

Posted by Hitesh Bhatia on January 12th, 2011

Taking MYSQL dump is usual requirement in my project . And Since some of the tables in project are huge so often I have to take dumps of selected tables and often have to ignore some tables.

since we had to do it frequently in our project so I created a script  which does following for me.

  1. Takes database dump
  2. Takes dump of specified tables.
  3. Takes dump of all the tables other than specified.

Inside the script I have added variables like username and password which are required by Mysql. (So if you are using this ,you will need to change them.)

USER="username"
PASSWORD="password"
DATABASE="$1"
DUMPS="Dumps"
DUMPDIR="$DATABASE$DUMPS"
FILENAME="latest.sql"
cd;mkdir "$DUMPDIR"

if [ $# -eq 0 ]; then
	echo "Usage : <databasename> <tablename*>  # if table name(s) is specified only that/those table will be dumped"
	echo "Altername Usage : <databasename> -k <table(s)dToBeIgnored>"
	exit
fi

if [ $# -eq 1 ];then
echo "Dumping $DATABASE to  $DUMPDIR/$FILENAME"
mysqldump --user="$USER" --password="$PASSWORD" "$DATABASE" > ~/"$DUMPDIR"/"$FILENAME"
fi

COMMAND="mysqldump --user=$USER --password=$PASSWORD $DATABASE"
if [ $# -gt 1 -a $2 != "-i" ];
	then
     for i in $*
	 do
		 if [ $i != "$DATABASE" -a $i != "-i" ];then
			 $COMMAND $i > ~/"$DUMPDIR"/"$i.sql";
		 fi
	 done
fi

if [ $# -gt 2 -a $2 == "-i" ];
	then
	COMMAND2=" "
	for i in $*
	do
		if [ $i != "$DATABASE" -a $i != "-i" ];then
		COMMAND2="$COMMAND2 --ignore-table=$DATABASE.$i"
		fi
	done
	$COMMAND $COMMAND2 >  ~/"$DUMPDIR"/"$DATABASE"-"Ignored.sql"
fi

Now what this can be used in three ways -
(Note – I have named this script sqlDump and all of following examples use this name )

  1. ./sqlDump.sh databasename
    This will take a complete dump of all my tables in specified database and store it in file named latest.sql
  2. ./sqlDump.sh databasename table1 table2 … tablenN
    This will take dump of all tables specified.And will store them in file named – table1.sql , table2.sql … tableN.sql
  3. ./sqlDump.sh databasename -i table1 table2 .. tableN
    This will take dump off all the tables in database ignoring specified tables. And will store it in file named <databaseName>-Ignored.sql.

If file is executed without any arguments it will just describe its Usage
Note – All of these tables will be stored in directory named <databasename>Dumps in home directory.

(more…)

  • Share/Bookmark
Posted in Grails, Linux

Linux Trick for screen collaboration or shell sharing

Posted by Tarun Pareek on November 14th, 2010

In recent week, i got to know about really good way of collaborating the screen in a linux.
 
Let us take a scenario, Suppose User having name ‘B’ on the 5th floor of the company is having a problem/difficulty related to code execution, unable to figure out what to do?, and then he call the fellow guy who can help him out, but he is on 1st floor his name is ‘Lazy A’.
 
Lazy A guy is really lazy, so here come handy screen collaboration trick to help him out and save him from walking 4 Floors to reach 5th one (:phew!:)
 
Lazy A support guy open its terminal and perform the following tricks consisting of 4 steps:
 
1. ‘Lazy A’ remote login into the User B system through following command:

lazyA# ssh B

2. After that Lazy A logged in as super user B, on B machine

B# su - B

3. Now Lazy A is on the B machine logged in as super user B, and ‘Lazy A’ runs the following command,

B# screen -S sos

4. Then Lazy A guy ask B to run following command on his/her system :

B# screen -x sos

 
Note that same alias ’sos’ is being used by both in last 2 commands, and both guy are logged in as same user.
 
Actually the last two command cause both user session joined together in linux shell and now both users can type on there shell and see what other is typing or doing to fix the issue, and this is how lazy A help out the B without walking to 5th floors.
 
After providing help, ‘Lazy A’ terminate the session by performing ctrl-C and then ctrl-D command on its terminal. Thats the way they get detach from each other and get back to there respective work.
 
And code happily ever after :)
 
Example to Test command on your machine:
 
To test the ’screen -S’ and ’screen -x’ command you can open two separate terminal or shell on your linux system, then run following command on your 1st terminal or shell
 
Terminal 1:

# su - tarun
tarun# screen -S mytest

And run another command on Terminal 2:

tarun# screen -x mytest

Then type on any screen you will see what you are doing on one is appearing on both the shells. To terminate session use ctrl-C and then ctrl-D. :)
 
Regards,
Tarun Pareek
LinkedIn

  • Share/Bookmark
Posted in Linux, System

Linux – Managing applications running on system start-up

Posted by Himanshu Seth on July 14th, 2010

Rcconf is a tool that we recently discovered. This tool allows you to manage your start-up applications easily.

We found this tool when me and my colleague Aman were trying to identify the processes that we never use but they do eat up a lot of our system resources. We found this link very useful: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html.

The other way to manage system start-up applications is as the page suggests, by using update-rc.d, but rcconf provides an interface which is easy to understand and use.

To install rcconf, run the following command on your command line:

sudo apt-get install rcconf

To run rcconf, you’ll need sudo privileges:

sudo rcconf

The application looks like :

* means that application is a part of startup
Use spacebar to uncheck the application

Save the settings and restart your linux box. I removed unused applications like postgres, tomcat, monit, bluetooth etc.

And my system does feel a bit faster :)

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Posted in Linux, System

Script for Running Grails Projects of Different Versions Simultaneously

Posted by Vivek Krishna on June 18th, 2010

Sometimes it is required that multiple Grails projects, each of them running on a different Grails version, run simultaneously esp. if one is fixing bugs and bringing up the application after switching the Grails version each time.
I wrote a utility shell script “runGrails” to use a particular version of Grails while running the scripts like run-app, test-app etc. The shell script contained these two lines:

export GRAILS_HOME=/opt/grails-$1
$GRAILS_HOME/bin/grails $2

This script was put in a location coming under the “PATH”. It is assumed that the different versions of grails are under directories named grails-<version> under /opt/.

Now, to run different projects, we can call the script as:

runGrails 1.3.1 "-Dserver.port=8082 run-app"

which will run the project with grails version 1.3.1 at port 8082.

PS: This works on *nix systems.

Hope this helps.

– Vivek

vivek[at]IntelliGrape[dot]com

  • Share/Bookmark
Tags: ,
Posted in Grails

How to Set-up shared folder/repository between two or more users on Linux

Posted by Himanshu Seth on June 14th, 2010

We had a case where we wanted two different applications (run by different users) to be able to read and write from the same file system.
This is how we solved this problem:

  1. Create a group which these users will belong to : groupadd <GroupName>
  2. Edit user1 and user2 to be a member of this group: usermod -a -G <GroupName> user1 & usermod -a -G <GroupName> user2
  3. Create a shared directory. In our case, it had to be the document root for an Apache site. Thus we chose the location <Shared_Folder>
  4. Now we need to change the group of this folder : chgrp -R <GroupName> <Shared_Folder>
  5. We’ll also need to grant the group write access on this folder : chmod g+w <Shared_Folder>
  6. Now we’ll need to set the GroupID flag on this folder. For a directory, the set-groupID flag means that all files created inside that directory will inherit the group of the directory. Without this flag, a file takes on the primary group of the user creating the file. This property is important to people trying to maintain a directory as group accessible. The subdirectories also inherit the set-groupID property. (http://www.dartmouth.edu/~rc/help/faq/permissions.html)
  7. Now in your .bashrc / .bash_profile, set the umask as 002. Setting this umask ensures that all the newly created files by this user will have the permission “rw-rw-r”. Thus giving the group write permission.

Now when either of the users create any file in the <Shared_Folder>, all the users of this group will have the read/write permissions on that file. Not only this, these permissions will be on the subfolders and the files with-in that folder as well.

But, if any of these users create a file outside the <Shared_Folder>, the primary group of that file/folder will be the same as the primary group of that user. Thus files/folder only in the <Shared_Folder> are shared between these users.

This is just one of the many great abilities that Linux provides.

Hope this saves you some time.

Your feedback and suggestions are welcome.

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Posted in Linux, System