Jaunty Jackalope is On

Yesterday Jaunty is really released. Now let's try it on and get the fastest Ubuntu boot with ext4.

welcome to utux-utux

The place where you can get any news, tipsn and tutorials about linux. I'cant explain any further informations about this site. Just open the tux image on the left side. ^_^

Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Add Mass of Clarkconnect Users From Text File

Don't even try to add user from shell with useradd in Clarkconnect. Why? It's because the linux user database is also used for the ldap database (see previous posting of me). If you do it, even the user is registered to linux user but the user won't be able login with his ldap account. You can only add the user within webconfig. The fact is database for linux user and ldap user is different.
The problem begin here. What about adding mass of users, for me 6000, users to the ldap systems. I've thoughted we can easily solve the problem with shell script. Right? But that's actually wrong. So what we gonna do now?
After look after Clarkconnect forum, I founded it. A script to add mas of users automatically from text file. But don't worry, this time the ldap user also would be made.

First, made a text file for username named user_list.txt and put it to /tmp folder. Form for the text is:
USERNAME1:UID:PASSWORD:FIRSTNAME LASTNAME
USERNAME2:UID:PASSWORD:FIRSTNAME LASTNAME
USERNAME3:UID:PASSWORD:FIRSTNAME LASTNAME
....etc

You can easily convert your database to .csv file type and replace the commas (,) with (:).

Then make the main script named user.php. This script can you put within your home folder.
#!/usr/webconfig/bin/php -q

///////////////////////////////////////////////////////////////////////////////
//
// Copyright 2003-2007 Point Clark Networks.
//
///////////////////////////////////////////////////////////////////////////////
//
// 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.
//
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////

/*****************************************************************************/
/* D E P E N D E N C I E S */
/*****************************************************************************/

require_once("/var/webconfig/api/User.class.php");
require_once("/var/webconfig/api/File.class.php");
require_once("/var/webconfig/api/UserManager.class.php");
error_reporting(0);

$file = new File("/tmp/user_list.txt");
if (!$file->Exists()) {
echo "File not found.\n";
return 1;
}

$lines = $file->GetContentsAsArray();
foreach ($lines as $line) {
$userinfo = array(
'dn' => null,
'sn' => null,
'cn' => null,
'givenName' => null,
'uid' => null,
'title' => null,
'o' => null,
'ou' => null,
'roomNumber' => null,
'street' => null,
'postOfficeBox' => null,
'postalCode' => null,
'l' => null,
'st' => null,
'c' => null,
'telephoneNumber' => null,
'facsimileTelephoneNumber' => null,
'kolabFreeBusyFuture' => 60,
'pol' => array('anyone' => 4),
'alias' => '',
'delegate' => '',
'cyrus-userquota' => '',
'kolabDeleteflag' => false,
'pcnFTPPasswordFlag' => true,
'pcnMailPasswordFlag' => true,
'pcnPPTPPasswordFlag' => true,
'pcnProxyPasswordFlag' => true,
'pcnWebconfigPasswordFlag' => true,
'pcnSambaPasswordFlag' => true,
'pcnWebPasswordFlag' => true,
);

$profile = explode(":",$line);
$user = new User($profile[0]);
if ($user->IsValidUsername($profile[0])) {
$username = strtolower($profile[0]);
$userinfo['uid'] = $username;
$userinfo['password'] = $profile[2];
$userinfo['verify'] = $profile[2];
}else{
echo "Invalid username (" . $profile[0] . ").";
return 1;
}
// protect root
if ($username == 'root') {
echo "Skipping root account...\n";
continue;
}

// protect system account
if ((int)$profile[1] < 1000) {
echo "Skipping system account (UID < 1000)...\n";
continue;
}

list($first, $last) = explode(" ", $profile[3]);

if ($user->IsValidFirstName($first)) {
$userinfo['givenName'] = $first;
} else {
echo "Invalid first name (" . $first . ").";
return 1;
}
if ($user->IsValidLastName($last)) {
$userinfo['sn'] = $last;
} else {
echo "Invalid last name (" . $last . ").";
return 1;
}

try {
$user->Add($userinfo);
$userinfo = null;
echo "User $username successfully imported!\n";
} catch (UserAlreadyExistsException $e) {
echo "User $username already exists...skipping.\n";
} catch (Exception $e) {
echo "Adding user $username failed - " . $e->GetMessage() . "\n";
echo "Bailing on user import...\n";
return 1;
}
}
return 0;
// vi: syntax=php ts=4
?>


The last one is just execute it
./user.php

Hope it helps for you all. And I also hope that the next version of Clarkconnect add function to add many users automatically just by import the file with webconfig.
^_^

DeepFreeze for Linux (Advance)

I have writen bout DeepFreeze for Linux before. But here, this script more compleks with Graphical Interface. Then, Let's Freeze your Linux.

Make a bash script named deepfreeze with this content first.

#!/bin/bash
# Deepfreeze a la Linux
# Backup before use, Use At Your Own Risk
# Copyleft 2007 by A. Hardiena
# Translated by fortmunir

Xdialog --title "Deepfreeze ala Linux" \
--menubox " Welcome to Deepfreeze ala Linux." 17 65 3 \
"Install" "Install Deepfreeze" \
"Remove" "Remove Deepfreeze"
"Abort" "Abort Installer" 2>/tmp/checklist.tmp.$$

choice=`cat /tmp/checklist.tmp.$$
rm -f /tmp/checklist.tmp.$$

case $choice in
"Install"

ask=`mktemp -q /tmp/menu.XXXXXX`
header="Deepfreeze ala Linux"
size="9 60"
content="Home folder you want to protect."
Xdialog --title "$header" --inputbox "$content" $size 2> $ask
if [ ! $?= 0 ]; then exit 0
fi

directory=`cat $ask`
check=`cat /etc//rc.d/rc.local | grep `# Deepfreeze System'`
temporary=" Deepfreeze System"

if [ "$check" == "$temporary" ]; then
sed -i "/# Deepfreeze/d" /etc/rc.d/rc.local
rm /home/$directory.tar.gz
fi
# Processing Deepfreeze and put to /etc/rc.d/rc.local
cd /home/
rm $directory.tar.gz
tar -cf $directory.tar $directory
gzip --best $directory.tar
cat << EOF >> /etc/rc.d/rc.local
# Deepfreeze System
cd /home/ # Deepfreeze do not manual editing this line
rm -f /home/$directory # Deepfreeze do not manual editing this line
# Deepfreeze has ended here
EOF
# Check if autorecovery has errorr
if [ $? = 0 ]; then
content="Deepfreeze home $directory success."
else
content="Deepfreeze home $directory failed."
fi

Xdialog --title "Header" --magbox "$content" $size
;;
Remove)
ask=`mktemp -q /tmp/menu.XXXXXX`
header="Deepfreeze ala Linux"
size="9 60"
content="Home folder you want to protect."
Xdialog --title "$header" --inputbox "$content" $size 2> $ask

if [ ! $? = 0 ]; then
exit 0
fi

directory=`cat $ask`


If your distro doesn't use rc.d but init.d, You should change position of rc.local from /etc/rc.d/ to the right directory.

The last step is change the mode
chmod +x deepfreeze

Just double cliks it to activate. Or type in your console sh deepfreeze.

Easy Command Easy Remoting

If we have to manage a group of computes, we sometime need to do a simple task in all computes. How do you do that? Log in to each computer and type the command? It’s very tiring and boring isn’t it? I have a tips that can make your life easier :)

This is the summary:
Create password-less root account in the cluster. No.. not that kind of password-less account. I’ll tell you later.
Make a simple script that will send a command to all computers.
Create a password-less root account
We will use a public/private key authentication scheme to login in a computer. To do this, we have to create a key pair and the private key should not be passworded. Why? If we create a password, we will have to type it again..
# ssh-keygen -t rsa


The command will create a key pair. Just press enter key several times until you found the command prompt again. You private and public key will be stored in your
~/.ssh
directory.
id_rsa
contains your private key and
id_rsa.pub
is your public key.

Copy your public key to authorized_users file in the same directory. So the sshd will look that file for the authentication process.
# cd ~/.ssh
# cp id_rsa.pub authorized_keys


Copy that 3 files into all computers in your cluster. Yes.. at this time, you have to type your password. But don’t worry, you will not do this anymore.
After that, you can test the password-less authentication by logging in to your another computer.
# ssh another.computer


Create a simple script to send a command to all computers
The script is very simple. Just a looping script that will iterate your computer addresses and give it to the ssh command.
Ssh can be used to run a command in a remote computer.
ssh some.address hostname


If we enter that command, we will make an ssh connection to some.address and run the hostname command in that machine. The standard input will be forwarded to remote machine and standard output/error will be forwarded to our local machine.
To send a command to a group of computers, we can use the following script.
# for addr in 192.168.1.2 192.168.1.3 192.168.1.4

> do

> ssh $addr halt

> done


The halt command will be sent to three computers (192.168.1.2, 192.168.1.3, and 192.168.1.4). So we can turn off more than one computers at a time.
If there is a pattern in your machine’s address, you can use the simpler variable.

# for addr in 2 3 4

> do

> ssh 192.168.1.$addr halt

> done


Tired of typing numbers? You can use seq command.
# for addr in `seq 2 4`

> do

> ssh 192.168.1.$addr halt

> done



All those three commands will do the same!

Here is one more example.
# for addr in `seq 11 26`

> do

> ssh 192.168.0.$addr mount -a

> ssh 192.168.0.$addr /etc/init.d/sgeexecd start

> done
 

different paths

college campus lawn

wires in front of sky

aerial perspective

clouds

clouds over the highway

The Poultney Inn

apartment for rent