Solved

Append input to file from script

Posted on 2008-06-24
7
297 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 P.S.
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 P.S.
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

680 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