HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Programming/Scripts (
-   -   Shell Scripting Help... (

webking 4th April 2007 17:51

Shell Scripting Help...
Hi all,

How difficult is it to get this pseudo code to work under SHELL? This is the task I do every day. I m not sure how to start it. can anyone help?

useradd username
usermod -g username username
passwd username
vi /etc/passwd
define home dir
cd ~username
remove all data
then go to /home/usrbak
cp username.tar.gz to /tmp
cd tmp
gzip -d username.tar.gz
tar -xf username.tar
mv * ~username
vi /usr/local/apache/conf/include-conf/vhosts
add the domain within the vhost
cd ~username
chown -R username:username .
chmod -R 755 .
service httpd restart

Any assistance would be helpful. Thanks in adv.

falko 5th April 2007 18:28

You could write a little script for it.

cfajohnson 19th April 2007 19:13

Most of what you are doing can be done with useradd itself. Read the man page.

The (moderately) tricky part is encrypting the password. I use a compiled C program as a front end to crypt(3):

NAME: crypt.c
AUTHOR: Chris F.A. Johnson
DATE: 2003-01-23
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

main(int argc, char *argv[])
char *passwd;
char buf[1024];
char *salt;

if (argc > 1)
salt = argv[1];
/* salt = "$1$!@#$%^&*"; */
salt = NULL;

if ( buf[strlen(buf)-1] == '\n' )
buf[strlen(buf) - 1] = '\0';
printf( "%s\n", encrypt(buf, salt));

return 0;

Do not use vi in a script. Describe what you want to do, and script it directly.

sjau 19th April 2007 20:13

Well, I think it's not that hard to make a bash script that does this...

All times are GMT +2. The time now is 11:02.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.