Solved

Append input to file from script

Posted on 2008-06-24
7
293 Views
Last Modified: 2010-04-21
Previously you all helped me create a script to add a user with some custom home folder stipulations. Now I'd like to modify the script to append $2 to /etc/ftpusers.

I've commented out the line I hoped would work for this purpose, but it overwrites the ftpusers file, instead of appending. Do I need to use cat instead?

Thanks!

****

mkuser:
if test $# -eq 0
then
      echo "Usage: ./mkuser firstname_lastname_location userid"
      exit 1
fi
#echo $2 >> /etc/ftpd/ftpusers
useradd -d /usr/igi/avante95/flodata/live/LIVE.DATA -c $1 $2
0
Comment
Question by:crcevans
  • 3
  • 2
  • 2
7 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 125 total points
ID: 21857510

echo $2 >> /etc/ftpd/ftpusers

Should (does) NOT overwrite the file.
0
 

Author Comment

by:crcevans
ID: 21857645
Now I have the following:

****
echo $2 >> /etc/ftpd/ftpusers
useradd -d /usr/igi/avante95/flodata/live/LIVE.DATA -c $1 $2
****
I need $2 on a new line in ftpusers, instead of appended to the previous line. How do I do that?
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 21858819

Try:
echo -e "\n$2" >> /etc/ftpd/ftpusers


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:crcevans
ID: 21859328
For whatever reason, the original echo statement is what is working.

Thanks for your help!

****final script****
# more /home/UN/mkt
if test $# -eq 0
then
      echo "Usage: ./mkuser firstname_lastname_location userid"
      exit 1
fi
echo $2 >> /etc/ftpd/ftpusers
useradd -d /usr/igi/avante95/flodata/live/LIVE.DATA -c $1 $2
0
 
LVL 16

Expert Comment

by:Hanno Schröder
ID: 21863297
Usually, the original file should have a newline (\n) at the end of it's
last line. Therefore, when you add something using
   echo "some stuff to add" >> myfile
it will get appended as another line, including another newline at
the end.
0
 

Author Comment

by:crcevans
ID: 21865190
Ah, so perhaps the fact that I edited the file in a windows editor and then FTPd it over is the reason it didn't have the /n on that last line the first time I tried your suggestion?
0
 
LVL 16

Expert Comment

by:Hanno Schröder
ID: 21865712
Windows (DOS) and Unix have different line endings:
- Unix has a newline (\n) at the end
- DOS has carriage return and newline at the end (\r\n)

If you transfer files from DOS (windows) to Unix using FTP in ASCII (or text)
mode, it will do the conversion for you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now