Visit Our UNIX and Linux User Community


exec a build command (adduser) in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting exec a build command (adduser) in a script
# 1  
Old 08-17-2009
exec a build command (adduser) in a script

Hi,

With a awk script i create a "adduser line"

$ cat /tmp/tmp.ldif | awk -f ldif2adduser.awk
adduser --uid 1002 --gid 1000 --gecos "ROUSSIN Guy" --home /homeL/guy --shell /bin/bash --disabled-password guy

If i cut and paste this line, all is fine. But in a shell script i get errors :

# cat t.sh
#!/bin/bash
# ADDUSER=`cat /tmp/tmp.ldif | awk -f ldif2adduser.awk`
ADDUSER="adduser --uid 1002 --gid 1000 --gecos \"ROUSSIN Guy\" --home /homeL/guy --shell /bin/bash --disabled-password guy"
echo ${ADDUSER}
${ADDUSER}


# ./t.sh
adduser --uid 1002 --gid 1000 --gecos "ROUSSIN Guy" --home /homeL/guy --shell /bin/bash --disabled-password guy
Warning: The home dir /homeL/guy you specified already exists.
adduser: The user `Guy"' does not exist.


The problem is when there is spaces in --gecos param.

I tried some workaround but without success.

Thank you.

Guy
# 2  
Old 08-17-2009
i found 2 ways,:

this i don't like so much
Code:
PART1="sudo adduser --uid 1010 --gid 1000 --home /homeL/guy --shell /bin/bash --gecos "
GECOS="ROUSSIN Guy"
PART3="--disabled-password guy"
${PART1} "$GECOS" $PART3

Code:
ADDUSER="sudo adduser --uid 1011 --gid 1000 --home /homeL/guy --shell /bin/bash --gecos \"ROUSSIN Guy\" --disabled-password guy2"
echo $ADDUSER >file_tmp.$$
sh file_tmp.$$
rm file_tmp.$$

# 3  
Old 08-18-2009
Thank you chipcmc. I use your second way very fine.
Quote:
Originally Posted by chipcmc

Code:
ADDUSER="sudo adduser --uid 1011 --gid 1000 --home /homeL/guy --shell /bin/bash --gecos \"ROUSSIN Guy\" --disabled-password guy2"
echo $ADDUSER >file_tmp.$$
sh file_tmp.$$
rm file_tmp.$$

Thank you again.

Guyr

Previous Thread | Next Thread
Test Your Knowledge in Computers #685
Difficulty: Medium
Reverse Polish notation (RPN), also known as Polish programming notation.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Script to monitor progress of find/exec command

hi all, i want to monitor the progress of a find and exec command, this is the code i use - find . -type f -exec md5sum {} \; >> /md5sums/file.txt this command works and produces a text file with all the md5sums but while running it doesnt show the progress is there anyway i can do this... (4 Replies)
Discussion started by: robertkwild
4 Replies

2. Programming

Bash script - find command with delete and exec

hi all, i have devised a script that starts in /restored/ and in there, there are a lot of sub folders called peoples names and in the sub folders are files/folders and it deletes the data in the sub folders BUT not the sub folder itself and it should then touch a file in all the sub folders... (3 Replies)
Discussion started by: robertkwild
3 Replies

3. Shell Programming and Scripting

Build.xml invocation by Build Script

Hi I have a build.xml file and I can run it on Windows via cmd. Now I want to write a script to invoke the same. Is there a way to do this? (1 Reply)
Discussion started by: ankur328
1 Replies

4. Shell Programming and Scripting

Use of exec command in a script

Guru's, I want to make a use of "exec" command in my script and want to check return code of executing script, but as you know exec command will terminate current processID and comeout and will trigger new one, i am unable to check return code of script and not able to run a scrpit after exec. ... (2 Replies)
Discussion started by: pawar.atul28
2 Replies

5. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

6. Shell Programming and Scripting

shell script for nessus-adduser

I took a stab at writing a script to automate the interactive process of adding users to Nessus - I have zero previous coding experience. So far, it doesn't get me anywhere. I took small sections of code from posts I found on this site and others:... (1 Reply)
Discussion started by: nolamiami
1 Replies

7. Shell Programming and Scripting

How to build a command in a script

Hi All I am trying to build a script that will take data from a tab separated file and use that to split up a quicktime file. So far the code is as follows #!/bin/sh #test parsing of data #fix excel file output returns cat $1 | tr "\r" "\n" > $1.fix printf "\n" >> $1.fix mv $1.fix $1 ... (3 Replies)
Discussion started by: babajuma
3 Replies

8. Shell Programming and Scripting

Please help: Build a sed command and execute it in a script

I am using an array to store some data (keys e.g 47975081_1215781266128), it can be assumed that it is key to other data. I want extract data from a file based on a couple of keys (range) and store the resulting data in a variable using the following command: sed -n... (9 Replies)
Discussion started by: gugs
9 Replies

9. Shell Programming and Scripting

question related to command "adduser"

Hello.. I dont know if i can ask this question in this session..if wrong please correct me.. This is my question.. When iam creating a user with command " adduser xxx" Where are the changes happening.. I know in /etc/passwd , /etc/shadow... in /home Is there any i missed.. please... (1 Reply)
Discussion started by: esham
1 Replies

10. Shell Programming and Scripting

Multiple exec command s in a script

Hi everyone, I've been racking my brains for ages on this and need your help/advice. I am writing a script that is reading in file to process and putting them into a temporary file. The loop starts and the script gets the first file name, does what i needs to do (copy it) and then returns to... (2 Replies)
Discussion started by: Angoss
2 Replies

Featured Tech Videos