Pages

Unixbhaskar's Blog

Tuesday, August 21, 2012

Create batch accounts of user automated way

I wrote a little and mundane script long time back to solve my purpose to create bunch of user accounts on specific host.

Here is the script:
#!/bin/bash
# This script is meant to run when we create a bunch of user account of any specified host.
#Backup important file before doing anything.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2,
# or at your option any later version, as published by the
# Free Software Foundation
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.


PASSWDFILE="/etc/password"

GROUPFILE="/etc/group"

SHADOWFILE="/etc/shadow"

DATE=`date`

USERFILE="THis file should have the form of password file like username:password:UID:GID:gecos:shell"

cd /etc ;pwd

cp -v $PASSWDFILE $PASSWDFILE.$DATE

echo " Password file backed up.."

cp -v $GROUPFILE $GROUPFILE.$DATE

echo " group file backed up.."

cp -v $SHADOWFILE $SHADOWFILE.$DATE

echo "shadow file backed .."


/usr/sbin/newusers $USERFILE

echo " Done"

echo " Forcing user to change their password upon first login.."

for i in $USERFILE

do

/usr/sbin/chage -d 0

echo $i

done


If you feel ,you can suggest me the enhancement.

Hope this will help.

Cheers!
Bhaskar

Wednesday, July 11, 2012

How to fix shell "permission denied" error

I believe everyone,who works on terminal for certain length of time come across this error sometime.

Very trivial topic so the fixing is also very trivial too.

Once you tried to logged into the shell you get the "permission denied" error on the console but get the shell prompt and most importantly you can not do a "ls" and other stuff too.

But you can login to the shell as root fine..without any error..it's the normal user that is getting it!!

So it signifies, something wrong with the way disk has been mounted.But once you give the correct flags with the mount it will work..but once you reboot it will started to react in same manner i.e erroneously.

How to do it right?

simple, put an entry like this in /etc/rc.local(that is file executed last at boot stage)

chown -R username:groupname disk-partition

I have had multiple disk partitions and I did that.

and make /etc/rc.local file executable by doing a chmod. Additionally check for /etc/nologin file..if that is present..then it might hinder you to get in.Double check the shell you are trying to use is exists.

That's all you need to do..next reboot it should be good.

Tip: Be careful about /dev/null! if the permission of this file get changed ;you might get the "permission denied" error too on console.So,you need to fixed that by running "mknod" to recreate it and assign the correct permission to this file.Normally it should look like this:

ls -al /dev/null
crw-rw-rw- 1 root root 1, 3 Jul 11 08:34 /dev/null


Udev plays a role to determine the right thing about those.So keep an eye on Udev related matters on system.


Hope this will help.

Cheers!
Bhaskar

Monday, April 23, 2012

Read the contents inside a RAM

In this post I will show you ,how you can see what is holding in your system RAM at the present moment.

Here is what you need to do :
bhaskar@GentooLinux_12:11:22_Mon Apr 23:~> sudo strings /dev/mem | less

And the outcome from my laptop is below:

ZRr=
`|f
\|f1
GRUB
Geom
Hard Disk
Read
Error
ZRr=
`|f
\|f1
GRUB
Geom
Hard Disk
Read
Error
loading
Geom
Read
Error
WVS1
[^_]
[^_]
>G9}
Ft51
D[^_]
[^_]
[^_]
Y_^+
RBRPQR
ZYs
(hd0,msdos2)/grub2
t)PS
USRf
fSfRQ
[_^]
UQPSVWR
_^[XY]
WVS1
[^_]
<,u; PAMS PAMSu [^_] [^_] [^_] u SSh, QQh< [^_] VVPh_ SSQht RRPh (<-t PWQh [^_] (<-t PQRh [^_] [^_] [^_] RPWh [^_] SSh/ PPhC PPhe t$QP [^_]Z [^_]Z s SSh% PPh6 [^_] [^_] (Ph] PPhn [^_] [_t3 [^_] [[t>
[^_]
[^_]
[^_]
4RPh
3w RRh
ELFu
PPh9
PPh\
PPhr
C09E
C09E
C09E
C09E
C09E
QPhY
t"RR
[^_]
[^_]
>PVWh
[^_]
[^_]
,[^_]
[^_]
RRhP
8(uB
PPh@
[^_]
RRhL
[^_]
>/t
[^_]
VVhq
[^_]
8+t 1
8+u< s VVh [^_] [^_] [^_] PPhP 8mimgu [^_] [^_]Z [^_] Y[^] WVSW ^[^_] ZY[^_] SWvP ^[^_] [^_] [^_] $[^_] [^_] u
Entering rescue mode...
grub_abort
grub_bios_interrupt
grub_boot_drive
grub_chainloader_real_boot
grub_checkkey
grub_command_list
grub_current_context
grub_device_close
grub_device_iterate
grub_device_open
grub_disk_ata_pass_through
grub_disk_close
grub_disk_dev_iterate
grub_disk_dev_register
grub_disk_dev_unregister
grub_disk_firmware_fini
grub_disk_firmware_is_tainted
grub_disk_get_size
grub_disk_open
grub_disk_read
grub_disk_write
grub_divmod64_full
grub_dl_get
grub_dl_head
grub_dl_load
grub_dl_load_file
grub_dl_ref
grub_dl_unload
grub_dl_unref
grub_env_export
grub_env_find
grub_env_get
grub_env_iterate
grub_env_set
grub_env_unset
grub_err_printed_errors
grub_errmsg
grub_errno
grub_error
grub_error_pop
grub_error_push
grub_exit
grub_fatal
grub_file_close
grub_file_read
grub_file_seek
grub_free
grub_fs_autoload_hook
grub_fs_list
grub_fs_probe
grub_get_rtc
grub_get_time_ms
grub_getkey
grub_gettext
grub_isprint
grub_isspace
grub_list_push
grub_list_remove
grub_machine_fini
grub_machine_mmap_iterate
grub_malloc
grub_memalign
grub_memcmp
grub_memmove
grub_memset
grub_millisleep
grub_mm_base
grub_module_iterate
grub_named_list_find
grub_parser_cmdline_state
grub_parser_split_cmdline
grub_partition_get_name
grub_partition_iterate
grub_partition_map_list
grub_partition_probe
grub_pit_wait
grub_print_error
grub_printf
grub_printf_
grub_prio_list_insert
grub_puts_
grub_pxe_call
grub_real_dprintf
grub_realloc
grub_reboot
grub_refresh
grub_register_command_prio
grub_register_variable_hook
grub_snprintf
grub_stpcpy
grub_strchr
grub_strcmp
grub_strcpy
grub_strdup
grub_strlen
grub_strncmp
grub_strncpy
grub_strndup
grub_strrchr
grub_strstr
grub_strtoul
grub_strtoull
grub_strword
grub_term_inputs
grub_term_inputs_disabled
grub_term_outputs
grub_term_outputs_disabled
grub_term_poll_usb
grub_unregister_command
grub_vprintf
grub_vsnprintf
grub_xasprintf
grub_xputs
grub_xvasprintf
grub_zalloc
memcpy
no gzip magic found
vga=791 is deprecated. Use set gfxpayload=1024x768x16,1024x768 before linux command instead.
no gzip magic found
Intel(R)Sandybridge Mobile Graphics Chipset Accelerated VGA BIOS
Intel Corporation
Intel(R)Sandybridge Mobile Graphics Controller
Hardware Version 0.0
A wHq}
s} K
!nr'
'Dj"f
w_{{
.}#
'8|+
|B&Y
f87N,
:N_>
3c#S?
;Q~P
%Iiil
:j )j#
npdZy
IU9#G
D*~1
x3&~
{JKK
( PT
0 5
8MJWP
133WH2
VESA
Intel(R)Sandybridge Mobile Graphics Chipset Accelerated VGA BIOS
Intel Corporation
Intel(R)Sandybridge Mobile Graphics Controller
Hardware Version 0.0
0 5
0 5
8MJWP
133WH2
WVS1
[^_]
[^_]
>G9}
Ft51
D[^_]
[^_]
[^_]
Y_^+
RBRPQR
ZYs
B>Sz~
,zD#i8
tX6p
.yn1
6lx3u
^Zm2
vXg{3
i[.b
uj!s
(ds&
O3L5
X 3vO
_iiZ
whvZ
qg?
mO''
y[hg4
wR;=
so_?
dOAj0X
zp}c\K~[
qRpd5
/o]`
D&X+
kfv[q
4t7M
.o#K &u
xn-9
aua*
]oS|(
8vzw
l[M(
@\!$
t,MEH
[NUe
iBi&
1.<& {I_6 (#lD .G;S ,ptl "(,B } 8+.O| Yo_g9m Pi&S C:9V `^[Ui ?cht xkpl !F{5 m UWw 6gK! ,- | ]-rB .Ywk t/{6 byX| jJ2& h*S& gOl".a {6_UE ru-L ^|xE, ^|oK :B:7 {0oR Ijg) 60Mq {/bn ey:h# x~mN n 5T4f }S+t Nen. x~+S& *HaY- TT8#B UJ;]h0 hnKd ] ?Y IU[~ A0K`D Sp"d HJ+~ 0$'%X 3]4@" I/Pl# 3\w^ ]W&@ u'ay 7kyn .xs6` A%Lxc BpUv gXJ,c U&L2OZ ~`8>Q_H
:WDH
f$S6
#q`E
nb%r
\;po
3i5~
|Vs-
T;t@
WN"K
HFcs
\U68
\A|?
|eI#
%Izg
3X1l
,lM;
|~4[8
#kO,*NgNt
Gd!o
D j"
^Fy!
\vz`
NfYBU
]gz1
\2g?
C@bi
T' Z52B
jtb{$p
fR{O_x
j>U`
~V/*A{k
.
.
.
.
$VBT SANDYBRIDGE-M d
BIOS_DATA_BLOCK
2098Intel(R)Sandybridge Mobile PCI Accelerated SVGA BIOS
Build Number: snm20980.dnq PC 14.34 12/22/2010 15:25:04
DECOMPILATION OR DISASSEMBLY PROHIBITED
Copyright (C) 2000-2003 Intel Corp. All Rights Reserved.
02468:<@BDFHJLPRTVXZ\ LFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelName 0@0p H?@0b 0@0p 0*x Q H?@0b @0 6 #@0 * q8-@X-6 0 5 LFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelNameLFP_PanelName+a fPfVfWf t[VfP ZYf;F rwfVWR . . . . . Diskette Drive Internal HDD USB Storage Device CD/DVD/CD-RW Drive Modular Bay HDD Onboard NIC Unknown device BIOS Setup Diagnostics eSATA CPU 1 Intel Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz To Be Filled By O.E.M. To Be Filled By O.E.M. To Be Filled By O.E.M. L1-Cache L2-Cache L3-Cache J1A1 PS2Mouse J1A1 Keyboard J2A2B Video J3A1 USB1 J3A1 USB2 J3A1 USB3 J5A1 J2B3 - CPU FAN J9E1 - SCAN MATRIX J9G1 - LPC SIDE BAND J2G1 - GFX VID . . . . DIMM_B BANK 2 Not Specified Not Specified Not Specified Not Specified vPro INTEL 0000 Dell Inc. 05/26/2011 Dell Inc. 0M516T .G2VKKP1.CN7016617J002I. To Be Filled By O.E.M. Dell Inc. Not Specified G2VKKP1 DELL2 OKP1 Dell Inc. Vostro 3350 Not Specified G2VKKP1 To be filled by O.E.M. 20110720 20110720 ATI Robson XT DIMM_A BANK 0 830B 35963CFC 0D111800 NT4GC64B8HB0NS-CG 110720 20110720 ptal ptalH ptalp ptal ptal pfr0 IFE$ $PMM G=fHf RSD PTR . . . . IBM COMPATIBLE IBM IS A TRADEMARK OF INTERNATIONAL BUSINESS MACHINES CORP. Dell System Vostro 3350 (C)1985-2009,American Megatrends, Inc.All Rights Reserved. $BV# A04$DEL R:EF8 !dhuS @t$j@ @((PP((PP,(-)*. AMIBIOS 080010 06/16/10(C)2010 American Megatrends, Inc. All Rights Reserved (C)2010 American Megatrends, Inc. 63-0100-000001-00101111-061610-Chipset 000-0-0000-00-00-0000-00-00-000 000-0-0000-00-00-0000-00-00-00-0 _TG_0AAAA000 AMIBIOS(C)2010 American Megatrends, Inc. BIOS Date: 05/26/11 10:52:20 Ver: 04.06.04 CCCC ???? <<<<


.... and many more...I have chopped out the rest for sake of brevity :-)

Hope this will help.

Cheers!
Bhaskar

Thursday, March 22, 2012

How to correct a small python code error!!

So, I was building a software which built on python2.6 version and I was exploiting it on CentOS 5.8.But when I ran the script I have come across that the script is throwing error and saying the syntax is invalid!! heck!

Although I have installed python2.6 separately on this box ...then what??

The error is ordinary :



sudo ./w3af_console -f
File "./w3af_console", line 108
rev = 0 if (a == 'HEAD') else -1
^
SyntaxError: invalid syntax


So , as next step I look into the script, which I should have done in first place and I couldn't.The problem lies in the first line of the script..as we all know that the shebang is the guide to system environment where the script are going to be interpreted.It was showing like this


#!/usr/bin/env python


Now I have corrected it ...as the software demands python2.6 ..so below..



#!/usr/bin/env python26



and Voila!!

Ordinary stuff right?? but tricky..might lead into long haul :)

Hope this will help.

Cheers!
Bhaskar

Tuesday, January 3, 2012

How to get over Gentoo's X display problem after update

Yep! I could have write the title more specific way,but let it go.So as normal routine I ran a worldsync on my Gentoo and bang! once I reboot the X was not coming up in-spite of having everything in place. What the heck!!!

Then,I realize that update make some enhancement to X and associated things are not getting updated with it.

So, instinctively poking at the log file tell me that "ABI version of so many thing ,related to X driver is mismatching with the server version" and then the obvious thing a little google search reveal that too.Something like this in log file shows:


38.004] (EE) module ABI major version (10) doesn't match the server's version (11)
[ 38.004] (II) UnloadModule: "vesa"
[ 38.004] (II) Unloading vesa
[ 38.005] (EE) Failed to load module "vesa" (module requirement mismatch, 0)
[ 38.005] (II) LoadModule: "fbdev"
[ 38.005] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so
[ 38.005] (II) Module fbdev: vendor="X.Org Foundation"
[ 38.005] compiled for 1.10.2, module version = 0.4.2
[ 38.005] ABI class: X.Org Video Driver, version 10.0
[ 38.005] (EE) module ABI major version (10) doesn't match the server's version (11)
[ 38.005] (II) UnloadModule: "fbdev"
[ 38.005] (II) Unloading fbdev
[ 38.005] (EE) Failed to load module "fbdev" (module requirement mismatch, 0)
[ 38.005] (II) intel: Driver for Intel Integrated Graphics Chipsets: i810,
i810-dc100, i810e, i815, i830M, 845G, 854, 852GM/855GM, 865G, 915G,
E7221 (i915), 915GM, 945G, 945GM, 945GME, Pineview GM, Pineview G,
965G, G35, 965Q, 946GZ, 965GM, 965GME/GLE, G33, Q35, Q33, GM45,
4 Series, G45/G43, Q45/Q43, G41, B43, B43, Clarkdale, Arrandale,
Sandybridge Desktop (GT1), Sandybridge Desktop (GT2),
Sandybridge Desktop (GT2+), Sandybridge Mobile (GT1),
Sandybridge Mobile (GT2), Sandybridge Mobile (GT2+),
Sandybridge Server, Ivybridge Mobile (GT1), Ivybridge Mobile (GT2),
Ivybridge Desktop (GT1), Ivybridge Desktop (GT2), Ivybridge Server
[ 38.005] (++) using VT number 7

[ 38.038] (EE) No devices detected.
[ 38.038]
Fatal server error:
[ 38.038] no screens found
[ 38.038]
Please consult the The X.Org Foundation support
at http://wiki.x.org
for help.
[ 38.038] Please also check the log file at "/var/log/Xorg.1.log" for additional information.
[ 38.038]




Now the time to rebuild the X11 drivers ,because I got new X server to match with it.Did it like this :



bhaskar@GentooLinux_15:11:04_Tue Jan 03:~> sudo emerge -1 $(qlist -IC x11-drivers)



That is numeric one to the emerge flag...means oneshot..means not put an entry in world file...

Once it finish I reboot the machine and voila...the X display come back!!

Hope this will help.

Cheers!
Bhaskar

Thursday, December 8, 2011

Using kvm on Arch Linux to install CentOS 6

This is mighty interesting and damn easy thing to do for better way to use and test new releases.I am gonna show you how you can exploit the power of KVM with minimal fuss.So here we go:

I am sitting on Arch Linux and got to bring in the kvm thing into the box..so I went ahead and do this :


bhaskar@ArchLinux_12:24:23_Thu Dec 08:~> sudo pacman -S qemu-kvm
resolving dependencies...
looking for inter-conflicts...

Targets (2): vde2-2.3.1-1 qemu-kvm-0.15.1-1

Total Download Size: 1.96 MB
Total Installed Size: 10.31 MB

Proceed with installation? [Y/n] y
:: Retrieving packages from extra...
vde2-2.3.1-1-i686 177.1K 58.0K/s 00:00:03 [#####################################################################] 100%
qemu-kvm-0.15.1-1-i686 1829.6K 62.8K/s 00:00:29 [#####################################################################] 100%
(2/2) checking package integrity [#####################################################################] 100%
(2/2) checking for file conflicts [#####################################################################] 100%
....
.....



Then I add myself to the kvm group like below:


bhaskar@ArchLinux_12:26:58_Thu Dec 08:~> sudo /usr/sbin/usermod -G kvm -a bhaskar

bhaskar@ArchLinux_12:27:12_Thu Dec 08:~> id bhaskar
uid=1000(bhaskar) gid=1000(bhaskar) groups=1000(bhaskar),92(audio),78(kvm)



Next, I modprobe two kernel module to integrate with the system like below:



bhaskar@ArchLinux_12:27:58_Thu Dec 08:~> sudo /sbin/modprobe kvm-intel

bhaskar@ArchLinux_12:28:10_Thu Dec 08:~> sudo /sbin/modprobe kvm



And the result shows like this :


bhaskar@ArchLinux_12:28:24_Thu Dec 08:~> sudo /bin/lsmod | grep kvm*
kvm_intel 116373 0
kvm 294406 1 kvm_intel



Then,the final step ,oh btw I have the ISO image of CentOS6 already downloaded in my system, so it easy to use...

So I went ahead like this to boot it from that ISO file by kvm:


bhaskar@ArchLinux_12:39:04_Thu Dec 08:~> qemu-kvm -enable-kvm -cdrom /home/bhaskar/Downloads/CentOS-6.0-i386-bin-DVD.iso


And here is how it look like the initial screen:



So ,pretty easy..huh..you can pass hell lot of option to that command line of qemu-kvm to fine tune you instances.

Hope this will help.

Cheers!
Bhaskar

Tuesday, December 6, 2011

How to get over Mutt's saga of "Unknown variables"

I have wrote an article about Mutt here . Now I have changed the system and trying to build it to different system and I am getting this errors:


bhaskar@GentooLinux_15:01:02_Tue Dec 06:~> mutt
Error in /home/bhaskar/.muttrc, line 12: imap_user: unknown variable
Error in /home/bhaskar/.muttrc, line 13: imap_pass: unknown variable
Error in /home/bhaskar/.muttrc, line 45: message_cachedir: unknown variable
Error in /home/bhaskar/.muttrc, line 58: smtp_url: unknown variable
Error in /home/bhaskar/.muttrc, line 59: smtp_pass: unknown variable
Error in /home/bhaskar/.muttrc, line 60: too few arguments



Pretty ordinary!! huh...no so..I was bemused for sometime then discover that when I pull in Mutt on Gentoo it failed to activate those flags and hence causing problem, here is the evidence of lacking those facilities:


bhaskar@GentooLinux_15:22:37_Tue Dec 06:~> mutt -v
Mutt 1.5.21 (2010-09-15, Gentoo 1.5.21-r1)
Copyright (C) 1996-2009 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.
Mutt is free software, and you are welcome to redistribute it
under certain conditions; type `mutt -vv' for details.

System: Linux 3.0.6-gentoo (i686)
ncurses: ncurses 5.9.20110404 (compiled with 5.9)
hcache backend: GDBM version 1.8.3. 10/15/2002 (built Aug 2 2011 22:18:59)
Compile options:
-DOMAIN
-DEBUG
+HOMESPOOL -USE_SETGID +USE_DOTLOCK +DL_STANDALONE -USE_FCNTL +USE_FLOCK
-USE_POP -USE_NNTP -USE_IMAP -USE_SMTP
-USE_SSL_OPENSSL -USE_SSL_GNUTLS -USE_SASL -USE_GSS -HAVE_GETADDRINFO
-HAVE_REGCOMP +USE_GNU_REGEX +COMPRESSED
+HAVE_COLOR +HAVE_START_COLOR +HAVE_TYPEAHEAD +HAVE_BKGDSET
+HAVE_CURS_SET +HAVE_META +HAVE_RESIZETERM
+CRYPT_BACKEND_CLASSIC_PGP -CRYPT_BACKEND_CLASSIC_SMIME -CRYPT_BACKEND_GPGME
-EXACT_ADDRESS -SUN_ATTACHMENT
+ENABLE_NLS -LOCALES_HACK +HAVE_WC_FUNCS +HAVE_LANGINFO_CODESET +HAVE_LANGINFO_YESEXPR
+HAVE_ICONV -ICONV_NONTRANS -HAVE_LIBIDN +HAVE_GETSID +USE_HCACHE
-ISPELL
SENDMAIL="/usr/sbin/sendmail"
MAILPATH="Maildir"
PKGDATADIR="/usr/share/mutt"
SYSCONFDIR="/etc/mutt"
EXECSHELL="/bin/sh"
MIXMASTER="mixmaster"
To contact the developers, please mail to .
To report a bug, please visit http://bugs.mutt.org/.

dgc.subjrx
fg.smarttime
vvv.initials
vvv.quote
vvv.nntp
patch-1.5.20hg.pdmef.progress.vl.2
rr.compressed
patch-1.5.4.lpr.collapse_flagged Lukas P. Ruf


The minus(-) prepended variables are not activated..so I need to activate them,which is causing trouble.

Now I need to reinstall mutt with all those enabled..so here we go :

First I have to set some use flags in /etc/portage/package.use/mutt.use file:


mail-client/mutt imap smtp pop gnutls mbox gpg smime sasl


And off I go to fetch Mutt one more time with those flags enable:


bhaskar@GentooLinux_15:35:56_Tue Dec 06:~> sudo emerge -av mutt

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild R ] mail-client/mutt-1.5.21-r1 USE="berkdb crypt gdbm gnutls* gpg* imap* mbox* nls pop* sasl* smime* smtp* ssl -debug -doc -idn -nntp -qdbm -sidebar -tokyocabinet" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

Would you like to merge these packages? [Yes/No] y



Look at the asterix appended values,which is exactly I did mentioned in the mutt.use file.


Now I can access Mutt without problem :)

Hope this will help.

Cheers!
Bhaskar