GAURAV KUMAR

Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Sunday, April 24, 2011

Rename multiple files with bash script

Hi there,
Recently I came up with a problem related to filename of downloaded files.In my college I use DC(Direct Connect) client to download files from other peers.Recently I downloaded a large number of music videos which remained in temporary directory and did not move to music directory.Although It downloaded completely, It remained in temporary directory and hence name of files was in the format "filename.(avi/mpg/flv etc.).(some chars).dctmp". So I had to rename them.Definitely, I couldn't do it manually as there were more than 1000 files.Hence I tried to write a bash script for renaming all of them at once.
Initially I tried to store the filename as "*.*.dctmp" in which I would trim the "*.dctmp" part.Hence the remaining part would the desired filename(with proper externsion).But storing the filename like that did not work out.
Then I saw that in temp files, there is a common pattern that before "dctmp" extension, there are exactly 39 chars. Then I tried a different method of trimming filename which is explained below with code.


code :

for i in *.dctmp
do
len="${#i}" ;
let len-=46
#echo "$len";
name="${i:0:len}" ;
#echo "$name"
mv "$i" "$name" ;
done

save it with name.sh and run "bash name.sh" on terminal.The script should be run in the same directory in which temp files are present.

e.g. Guns N' Roses - Welcome To The
jungle.mpg.47IMRQGAGFWOA7GMLZTK3X6QFIGR4P4EKHDRHKI.dctmp
became Guns N' Roses - Welcome To The Jungle.mpg

Worked on ubuntu 10.10

Monday, March 21, 2011

password reset from shadow file in ubuntu 10.10

Hi,
Recently I was trying to write a script for changing password automatically for a user.I required something else for this but I found one similar script while searching over Internet.While I was experimenting with this on my ubuntu 10.10 system, I did a terrible mistake.At the place of username, I put my main account username.Not only this,I used "pwgen" program to generate random password which was there in the script and I blindly used it.

The script I used is below:-

touch pass.txt
chmod 600 pass.txt

# generate a nice secure password and put it in a file
pwgen > pass.txt

# get the password hash
ph=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')

# Set the password
usermod -p $ph "username"


Now, first time I used it using sudo, It asked for password.Now this script randomly generated a new passowrd and set for my account.Now, a new password was hashed in /etc/shadow file which I didn't know.Next time, when I used it again,it asked for password which was changed randomly.So,I could not give correct password.


Now, I thought how would I login after next reboot.I asked someone who told me to use a live cd of ubuntu to change shadow file.In shadow file, password is stored encrypted corresponding to each username.Now, I was preparing for a back up.Still, I wasn't sure it will work.

When I rebooted,something clicked in my mind.I booted in recovery mode.Then using root shell, I opened /etc/shadow file.Usually it opens in read-only mode.But since I was root that time, I removed the hash of my username.I removed everything that was there between first 2 colon(:). I did it only for my username and root.Hence, password was omitted.Now I reboot again and reset the password using passwd command and it didn't ask for current password.I didn't know that we could reset our password in recovery mode.

I knew that this similar method worked in ubuntu 8.04. But I thought they removed this as a bug.Now it worked for me.I can't decide if it is a good or bad thing.Since I changed my password in emergency,It is cool. But someone else can access my account by resetting my password.

Thursday, September 2, 2010

UNSUCCESSFUL UBUNTU KERNEL UPGRADE TO 2.6.32-24


Hi all,
Just a month before 10.10 release,ubuntu 10.04 has created a problem for me.This post is more like a problem statement because I haven't figured out the solution yet.Last night I was upgrading my kernel to 2.6.32-24.After that my network manager was not running.I thought something was wrong with upgrade.So I rebooted and was shocked when I saw the grub menu.Previously, Grub menu used to show kernel versions 2.6.32-21, 2.6.32-22, 2.6.32-23 and their recovery options.Out of that 2.6.32-23 could not be used to boot.So,I used to boot through 22.But now,I could see only 23 and my system did not boot.when i tried to edit this option(generic kernel 2.6.32-23 in grub menu screen), I got first line as recordfail as shown in above image.

Then I tried to search on internet but found nothing important.Tried live cd of ubuntu 9.04 and tried to reinstall kernel.tried "sudo update-grub" and also grub-pc.Then checked /usr/src of 10.04 where I saw all previous kernel images along with 2.6.32-24.Now it looks like latest kernel couldn't be written but previous images were removed and only remained kernel is corrupt.So,I am not able to boot into ubuntu. Right now only solution is to reinstall 10.04.hoping a better solution from someone.

Monday, May 3, 2010

Download speed through apt-cacher and dependency problem with downloading so many packages at a time








hi,
I am not able to stop experimenting with ubuntu lucid lynx the time I installed it.With the apt-cacher,it's easy to download all the packages that you like.So,I was there with synaptic package manager and kept on selecting large number of packages.Finally I got a collection of 148 packages with 220 MB size.When I started to download,I saw variation of speed which is very common but I would like to point it out by some snap-shots.
1st picture shows the usual speed of download through apt-cacher which is 347 KB/s.2nd one shows unusual high speed 2843 KB/s.











But sometime we suffer low speed also.Just like this.


Now,apart from speed,there is one more thing that I would like to share.Since I selected a lot of packages and started downloading all,I got some installation problem.All the packages were downloaded but couldn't be installed properly.Very less packages were installed because of dependency problem.No idea how did it happen.Probably,when there is a huge number of packages ,some of them might have dependency due to others files in the download list.So,in my view,large number of packages should not be installed at a time.

By the way, I sent these dependencies report to developers officially.Here is one screen-shot which explains it.


Conclusion :- try installing less number of packages at a time.

Saturday, May 1, 2010

performance review of ubuntu 10.04 lucid lynx

hello friends,
Ubuntu launched its Final release of lucid lynx 10.04 just 2 days before and I couldn't stop trying it as soon as I could.Reason is not that I was waiting eagerly for its final release.Real reason is that I had done some mistake in hard disk partition while installing slackware which caused me loss of linuxmint which I was using for a very long time.So, finally I thought to try fresh and final release of 10.04.
oh boy,What an OS.Surprisingly it can be called as the perfect OS.Lookwise,it has got better.Also,the most exciting feature is its boot time.Amazing boot time must have impressed everyone.Shutdown time is also faster.This has got attention of some people who are claiming that skipping disk check can also reduce boot time.Anyway,I don't want to create any controversy here.
Talking about look,It gives a sight of mac.The minimize, maximize and close buttons of window is on the left side which gives you feeling of working on mac.Anyway that feature was available previously also but not as default(a package "mac4lin" changes the look in that manner).New Gwibber social client is also very exciting.Gwibber can be configured to broadcast status on facebook,twitter etc. and to see other's status.
Recently "ubuntu tweak" became my latest crush as It has got nice and sexy packages which synaptic package manager didn't let me try directly.visit ubuntu-tweak.com for more info about tweak.As I am in a university which does not provide with a superfast internet connection but allows downloading packages with apt-cacher,I couldn't stop downloading all the packages which caught my attention.Well,It's definitely wastage of resource.
In final words,ubuntu 10.04 is just lovable and awesome and great experience so far.Don't know how soon the bugs will come out.Till then,enjoy lucid lynx.Happy open source.

Wednesday, November 11, 2009

ubuntu 9.10 karmic koala performance on Deepak's Laptop

hello friends,
today i saw the performance of ubuntu 9.10(karmic koala).I didn't install it but my friend did in front of me.He had ubuntu 9.04 installed, so he tried to upgrade to 9.10 instead of installing.So, he made bootable USB of alternate disk.But, sadly we couldn't upgrade it.instead,we had installed 9.10 into separate partition. now he had 3 OS.
Finally we started testing it.First we tried to use pidgin client which wasn't there and we saw empathy.Empathy has become default IM client now in ubuntu.Still we downloaded pidgin and run.well, empathy is good change, i must say.Next we tried DC client and it was okay okay.And then accidently we removed open office for which he was blaming me. But I was only trying to install vlc.
Most of the things are same and it is showing different performance on different laptops.on acer laptop,my one friend could not use it and on dell studio it has graphics problem.Browsing is as fast as usual.one more new thing that i saw was,it asked for internet connection settings before installation which was optional. Rest,everything was good but not much impressive.I still think linuxmint is better option.May be, i should wait for sometime to be more sure.

Wednesday, November 4, 2009

linux mint experience

hello friends,

i recently tried windows7 RC version and ubuntu 9.04 jaunty.previously i had windows vista and ubuntu 8.10.So i thought to upgrade ubuntu as i liked it so much.on the other hand,vista compelled me to replace it.so i switched to windows7.definitely it was faster than vista but certainly not stable enough to impress.well, i am not professional in this field to judge accurately but i am interested in trying different and new and efficient products.
It is just a week ago that ubuntu has released its 9.10 karmic alpha version.So, my friends have downloaded it and some have started using this while i am still waiting for its stable version.Last night when i thought to try a new distro of linux, I tried to surf our college website bitsfoss which is a repository of open source stuffs.I downloaded linux mint 7 gloria.I put this in USB and made it bootable through ubuntu's cool application "start up disk".

Finally I used mint as live cd and it was awesome.I just loved it.the display is undoubtedly better than ubuntu.since i have just tried it,i can't say more. But if anybody is really interested,one can visit here.

Now that ubuntu has released its alpha3 of karmic koala, I am excited to compare with it.But first I should wait for its final release.

if anybody reads it, i would ask them to vote for either mint7 or ubuntu9.10 in comment.

Tuesday, July 14, 2009

restoring grub menu

hi people,
finally pushed myself to write one about a technical issue. recently ,I reinstalled windows vista successfully but after restart i didn't see any grub menu to boot linux(ubuntu).At that instant, i was shocked as i thought linux was gone.Since vista had overwtitten the mbr so it used to boot vista directly.I tried to restore grub menu through a live cd of linux which is done through typing some commands in terminal.Basically, anybody can copy those commands from www.ubuntuforums.org . But those commands were useless for my system as the "stage1" file was washed away from grub folder.finally,i downloaded an iso image of "super grub disk" and made a cd. then i booted through that cd and everything started working fine.when i saw grub menu again, i was so happy.