Pls post execution log (set -vx) with err msg.
On first sight, you may try double quotes if [[ "$?" -eq "0" ]]. Secondly, you may want to save $? to a variable and echo it for reference.
AND, on third sight, you are testing $? from the assignment old=_old which succeeded and thus $? is 0. So - go with the second proposal, use a variable.
Last edited by RudiC; 01-06-2013 at 04:47 AM..
Reason: Third sight
Pls post execution log (set -vx) with err msg.
On first sight, you may try double quotes if [[ "$?" -eq "0" ]]. Secondly, you may want to save $? to a variable and echo it for reference.
AND, on third sight, you are testing $? from the assignment old=_old which succeeded and thus $? is 0. So - go with the second proposal, use a variable.
Heres the error log :
i tried putting double quotes but no luck.
PS: neha is first username in userlist.
---------- Post updated at 09:25 PM ---------- Previous update was at 09:09 PM ----------
i think the return code is 0 because we're creating the home dir in the createUser() function. here :
here we're using "useradd -m" to create a home dir for the given user. which in turn gives the return code as 0.
did i get it correct? or if am wrong, then how to modify the code to resolve the error as well as to fulfill the purpose of script?
Again, output the $? after the cd command and after the assignment.
And, I'm pretty sure, the user directory will be created in useradd. So you need to check not for presence of dir, but for non-/ emptiness.
Again, output the $? after the cd command and after the assignment.
And, I'm pretty sure, the user directory will be created in useradd. So you need to check not for presence of dir, but for non-/ emptiness.
log showing return code after
and
If possible, could you please modify the script for me? It would be great help.
Pls post logs as text files, not screen shot images.
So, as the directory exists, you want to check if it's empty. After successfully cding to /neha, try sth like ls|wc -w. If that supplies anything different from 0, the dir is not empty and you should ask for overwrite.
Pls post logs as text files, not screen shot images.
So, as the directory exists, you want to check if it's empty. After successfully cding to /neha, try sth like ls|wc -w. If that supplies anything different from 0, the dir is not empty and you should ask for overwrite.
This is ful log report using
after assignment
. Its showing that the dir is empty but still asking to overwrite. Return code after
is also 0.
Also if the answer for overwriting is "NO", the script doesn't create $user_old dir and simply copies files in current dir.
. . .
Its showing that the dir is empty but still asking to overwrite. Return code after
is also 0. . . .
Fine - but here we don't need the exit code, but the word count itself - i.e. the no. of files in dir:
DON'T execute any command before evaluating the exit code - it will contain the last command's status, in the case above echo's status, which is almost always 0, rendering $? useless for your purposes. Save exit codes into e variable immediately for later evaluation!
Quote:
Also if the answer for overwriting is "NO", the script doesn't create $user_old dir and simply copies files in current dir.
Can't tell why - but the entire logics of your function needs some polishing. Step back and start from scratch - where do you come from? What do you want to achieve? E.g. there's four options - copy into empty dir, overwrite with or without saving old files, or don't copy at all. Try to sketch that on a paper slip and then start over coding. Setting the shell's -vx options helps troubleshooting as it prints out what the shell does.
I need a script to add the following two users ids to the permissions for various files: IIS_WPG and IUSR_CowGirl. I am fairly familiar with scripting but haven't been able to figure out how to do this via a script. Manually doing it is slow. I don't want to create users but only add them to a... (2 Replies)
I need a script to add the following two users ids to the permissions for various files: IIS_WPG and IUSR_CowGirl. I am fairly familiar with scripting but haven't been able to figure out how to do this via a script. Manually doing it is slow. I don't want to create users but only add them to a... (2 Replies)
I apologize if this is a simple/stupid question. When I add users in smit as root, many(most) of the fields are automatically popluated with some basic default values.
Some other admins here have access to create users via sudo, however when they create users (sudo smit users), the user gets... (3 Replies)
Go easy on me - first post
I need a simple script that will mount a directory in the /home folder of all users. I need to run this on boot and regular intervals as a cron job. I was hoping to achieve this by modifying fstab but it is not possible and I would like to avoid symlinks.
I have... (7 Replies)
Hello there,
I want to add new users to my system, so, being logged in as root I do useradd -m user_name, and the new user is added to the system. The problem is that it has more privileges than I expected. If I do su user_name then I am allowed to do cat /etc/passwd , so it is... (4 Replies)
Hi guys!
Just was wanting to run a command that would allow me to seperate the currently logged in users.
Basically from this format:
user1
user2
user3
To:
user1|user2|user3
(Note the lack of a pipe at the end, not sure if thats possible)
Basically it needs to be in this... (11 Replies)
Hi ,
Thanks for your time .
I am working on a application , which adds unix user through useradd and deletes user through userdel . both are admin commands .
My requirement is i have to add a user into at.allow whenver a unix user is added through my application and the user should be... (4 Replies)
I'm using SAM to add users on an HP and they're adding fine. But in /etc/group it only lists the group names. It's not adding the users in there. Is there a way to have them put in there without going into SAM and modifying the group and adding them? I guess what I want to happen is when I add... (1 Reply)
Hi,
I need to convert user-input from '(this)' to '\(this\)' before passing it to egrep. I've tried using TR, SED and NAWK to add the backslash, but the most I ever get is a backslash without a '(' or ')'.
Any ideas?
Thanks! (13 Replies)