# find . -mount -mtime -5 -exec du -sk {} ; | sort -n
93/433
Month: January 2011
build an iso image
if you want to make a cdrom image of a file, you can just run:
mkisofs -o the_iso.iso -R -v the_file.tar.gz
92/433
Disable password aging for a particular account using “chage”
If you want a user’s password to never expire use:
# chage -I -1 -m 0 -M 99999 -E -1 theuser
If you just want to check the user’s password expiry then
# chage -l theuser
# passwd -Sa | grep -i theuser
Adding udev rules
I inspected all the devices i wanted to add to udev using “udevadm info” for each path i knew was the device i needed.
udevadm info -a -p $(udevadm info -q path -n /dev/video1)
udevadm info -a -p $(udevadm info -q path -n /dev/video0)
udevadm info -a -p $(udevadm info -q path -n /dev/input/mouse1)
udevadm info -a -p $(udevadm info -q path -n /dev/input/event1)
udevadm info -a -p $(udevadm info -q path -n /dev/input/event2)
udevadm info -a -p $(udevadm info -q path -n /dev/input/mouse2)
Then just created the udev file /etc/udev/rules. d/95-my.rules
KERNEL==”video*”, SUBSYSTEM==”video4linux”, ATTR{name}==”saa7133*”, SYMLINK+=”tvcard”
SUBSYSTEM==”video4linux”, ATTR{name}==”gspca main driver”, SYMLINK+=”geniuscam”
KERNEL==”mouse*”, ATTRS{name}==”Microsoft Basic Optical Mouse”, SYMLINK+=”input/cecimouse”
KERNEL==”event*”, ATTRS{name}==”AT Translated Set 2 keyboard”, SYMLINK+=”input/cecikb”
KERNEL==”event*”, ATTRS{name}==”Logitech Logitech USB Keyboard”, SYMLINK+=”input/betokb”
KERNEL==”mouse*”, ATTRS{name}==”USB Optical Mouse”, SYMLINK+=”input/betomouse”
reboot, and i get pretty aliases for all my devs 🙂
soft partition create, grow, delete on SVM (Sun Volume Manager/Solstice Disksuite)
You have a parition d50 comprising slice 0 of a disk:
d50 1 1 c7t60060E80042AEE0000002AEE00000019d0s0
now you want to create soft partitions in it, you can create a 5gb soft partition just by:
# metainit d55 -p d50 5gb
# newfs /dev/md/dsk/d55
You can destroy it by unmounting it, and clearing it
# metaclear d55
You can grow this partition
# metattach d55 1gb
# growfs -M /mount/point /dev/md/rdsk/d55
261/433
Multiseat xorg+gdm on slackware 13 x86_64
One computer, two people using it, that means
– 2 video cards, one in the motherboard, and another in PCI-E
– 2 monitors, 2 keyboards, 2 mouses
lspci says:
root@kraftek:~# lspci | grep -i vga
02:00.0 VGA compatible controller: nVidia Corporation C77 [GeForce 8200] (rev a2)
03:00.0 VGA compatible controller: nVidia Corporation G98 [GeForce 8400 GS] (rev a1)
Make sure you select the pci-e as the first card to be initialised in the bios
To find out which mouse and keyboard is which, for each /dev/input/mouse1 /dev/input/mouse2 and /dev/input/event0 /dev/input/event1 /dev/input/event10 /dev/input/event11 /dev/input/event12 /dev/input/event13 /dev/input/event2 /dev/input/event3 /dev/input/event5 /dev/input/event7 /dev/input/event8 /dev/input/event9 do a:
# cat /dev/input/mouse X
# cat /dev/input/eventX
and move the mouse or type in the keyboard, if you see characters in the terminal, that is your kb or mouse.
Also make sure you enable this on the ServerFlags section in xorg.conf so that xorg honors the devices you
select in xorg.conf
Option “AutoAddDevices” “false”
/etc/X11/xorg.conf
30/433
/etc/X11/gdm/custom.conf
The gdm custom.conf is necessary so you have 2 login screens, one on each screen, the important part is:
[servers]
0=Standard device=/dev/console
1=Standard1
[server-Standard]
name=Standard server
command=/usr/X11R6/bin/X -nolisten tcp -novtswitch -sharevts -layout seat1
flexible=true
[server-Standard 1]
name=Standard server
command=/usr/X11R6/bin/X -nolisten tcp -novtswitch -sharevts -layout seat2
flexible=true
enjoy!
31/433
socktest
Have you ever wanted to test a connection to only one port, and found nmap overkill, and you like to do it in C?
Normally I’d recommend something like
echo “~.” | telnet -r $H $X 2>&1| grep -i connected | wc -l | sed ‘s/ //g’`
But, if the host doesn’t answer the default tcp/ip timeout for a socket is 3 minutes!!!! You have to wait long
time…
You don’t want to wait too long for that, so you can use a program to test a socket connection, like socktest.c,
it tries to connect and if it can’t within 5 seconds it will bail out.
you should compile with gcc, if using solaris “gcc -o socktest -lsocket -lnsl socktest.c” will suffice.
So, for instance you want to test port 80 and port 44 in google.com:
bash-3.00$ ./socktest google.com 80 ; echo $?
Connection to port successful
bash-3.00$ ./socktest google.com 44 ; echo $?
ERROR: Timeout or error() 4 – Interrupted system call
1
You can get the exit code 0 as successful, 1 as not successful.
Source here:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <sys/fcntl.h>
//—————————————–
// Roberto Dircio Palacios-Macedo
// socktest – program to test a connection
// to a host in a specific port
// usage – ./socktest <host> <port>
//—————————————–
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
80/433
{
int res,valopt;
struct timeval tv;
fd_set myset;
socklen_t lon;
int soc, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc < 3) {
fprintf(stderr,”usage %s hostname portn”, argv[0]);
exit(1);
}
portno = atoi(argv[2]);
server = gethostbyname(argv[1]);
soc = socket(AF_INET, SOCK_STREAM, 0);
if (soc < 0) {
error(“ERROR: opening socket”);
exit(1);
}
if (server == NULL) {
fprintf(stderr,”ERROR: no such hostn”);
exit(1);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
long arg = fcntl(soc, F_GETFL, NULL);
arg |= O_NONBLOCK;
fcntl(soc, F_SETFL, arg);
res=connect(soc, &serv_addr,sizeof(serv_addr));
if (res < 0) {
if (errno == EINPROGRESS) {
tv.tv_sec = 5;
tv.tv_usec = 0;
FD_ZERO(&myset);
FD_SET(soc, &myset);
if (select(soc+1, NULL, &myset, NULL, &tv) > 0) {
lon = sizeof(int);
getsockopt(soc, SOL_SOCKET, SO_ERROR, (void*)(&valopt) , &lon);
if (valopt) {
fprintf(stderr, “ERROR: Error in connection() %d – %sn”, valopt, strerror(valopt) );
exit(1);
}
}
else {
fprintf(stderr, “ERROR: Timeout or error() %d – %sn”, valopt, strerror(valopt) );
exit(1);
}
}
81/433
else {
fprintf(stderr, “ERROR: Error connecting %d – %sn”, errno, strerror(errno)) ;
exit(1);
}
}
arg = fcntl(soc, F_GETFL, NULL);
arg &= (~O_NONBLOCK) ;
fcntl(soc, F_SETFL, arg);
fprintf(stdout, “Connection to port successfuln”);
exit(0);
}
Enjoy!
82/433
remove “.” from PATH in SLES11
if your $PATH includes “.” you need to edit /etc/sysconfig/suseconfig and set
CWD_IN_USER_PATH=”no”
CWD_IN_ROOT_PATH=”no”
20/433
Get raw device size in sles
To get this:
myserver:~ # ./rawsize.ksh
raw1 : Disk /dev/sdb: 54 MB, 54525952 bytes : 52 mb
raw2 : Disk /dev/sdc: 314 MB, 314572800 bytes : 300 mb
raw3 : Disk /dev/sdd: 20 MB, 20971520 bytes : 20 mb
raw4 : Disk /dev/sde: 31 MB, 31457280 bytes : 30 mb
raw5 : Disk /dev/sdf: 31 MB, 31457280 bytes : 30 mb
raw6 : Disk /dev/sdg: 31 MB, 31457280 bytes : 30 mb
raw7 : Disk /dev/sdh: 31 MB, 31457280 bytes : 30 mb
raw8 : Disk /dev/sdi: 17.1 GB, 17179869184 bytes : 16384 mb
raw9 : Disk /dev/sdj: 17.1 GB, 17179869184 bytes : 16384 mb
raw10 : Disk /dev/sdk: 838 MB, 838860800 bytes : 800 mb
You need a script called rawsize.ksh with this:
cat /etc/raw | grep -v ^# | while read d;do
a=`echo $d | awk -F: ‘{ print $1}’`;
b=`echo $d | awk -F: ‘{ print $2}’`;
c=`fdisk -l | grep -i $b`;
d=`grep $b /proc/partitions | awk ‘{print $3}’`
s=`echo “$d / 1024” |bc`
echo “$a : $c : $s mb”; done 2>&1 | egrep -iv ‘/dev/dm|valid’
5/433
Extended Diagnostic Boot
1. Break the system to the open boot prom by issuing a Stop+A
2. Set the following parameters from the ok prompt:
setenv auto-boot? false
setenv diag-switch? true
setenv diag-level max
setenv diag-device disk
3. Alternately, you could set the parameters from the system level:
eeprom “auto-boot?=false”
eeprom “diag-switch?=true”
eeprom “diag-level=max”
eeprom “diag-device=disk”
4. Turn the system off. Wait about a minute, then turn it back on.
73/433