Solved

Append input to file from script

Posted on 2008-06-24
7
292 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

760 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

16 Experts available now in Live!

Get 1:1 Help Now