Solved

Append input to file from script

Posted on 2008-06-24
7
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

691 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