Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok, My problem is that everytime I try to run this script (accounts.csh)
./accounts.csh f 101 103
-103: No such file or Directory
./accounts.csh f 101 105
-105: No such file or Directory
./accounts.csh f 101 108
-108: No such file or Directory
So, this is what I have so far.
#!/bin/csh
set letter=$1
set start=$2
set end=$3
set password="foobar"
set group=10
set path=/export/home
set shell=/bin/sh
while $start<-$end
set logine=$letter
set logine=$logine$start
echo "$logine":"$password":"$start":"$group":"$logine":"$path/$logine":"$shell">>/etc/passwd
Thank you very much Mr. Cheesus that fixed the problem and then I needed to add the "end", but for some reason it is not creating the accounts. I was thinking that there is a command that pipes the error messages into a file I am not sure about that command but I believe is something like
./accounts.csh f 101 103 >> 0 /home/user/Desktop/file.txt something like that, can anybody confirm that please? other wise I will ask google, thank you.
---DELETED BECAUSE IT WAS TERRIBLY WRONG---
But be careful, do not destroy your /etc/passwd, or you will never again log in ;-)
Better use useradd, adduser, or similar, depending on your distribution.
Cheers!
I swear I was sober when I wrote the above, but it's of course terribly wrong.
">" is write to stdout
">>" is append to stdout
"2>" is write to stderr
"2>>" is append to stderr
so actually ">>/etc/passwd" should have worked,
if you ran the script as user root
and if your system doesn't use /etc/shadow
but of course useradd, useradd or similar is still a good idea.
Cheers, Tom.
I didn't have any problem with the passwd/shadow files. But I am wondering if I am concatenating correctly the line of
logine=$letter
logine=$logine$start
Is this correct? Thank you for your help.
Ok I found out that in order to concatenate I just need to put one variable next to the other such as in this exmple.
There is no concatenation operator. To concatenate strings, put them one next to the other.
set newstring = aaa$string1${string2}bbb
So, what I don't understand is why when I run the script as :
./accounts f 101 103 2> errors
$cat errors
cat: f: No such file or directory
cat: 101: No such file or directory
cat: 103: No such file or directory
Well, since f/101/103 are your params, you're probably executing $1/$2/$3.
Actually, I thougt putting the paranthesis () to while would solve that.
I any case, you need to post the current version of your script...
As I have been working on the script I found this command which tells me what lines work.
So now when I type: csh -x ./accounts.csh f 101 103
shows:
set letter=f
set start=101
set end=103
set password=foobar
set group=10
set path=/export/home
set shell=/bin/sh
set logine=f101
while ( 101 -le 103 )
while: Expression Syntax.
Which means that there is a problem with the syntax of the while loop, but I have been looking and I see no problem with the while loop. I will try to do it with ksh and see if it works.
Well, I have checked every line of the script and browse the internet to look up for the syntax of the while loop for csh and I couldn't find any thing that would help me. Yes I found many places that showed me how the syntax goes but nothing different to what I had. So, what I decided to do is to re-do it in korn shell and it seems that it worked now. I just have to wait to go to the class room and run it, but it works in my machine. Thank you for your help cheesus & Chrism01. I will post my script as soon as I finish the test of Calculus tomorrow.
Last edited by bartsimpsong; 10-11-2011 at 11:28 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.