Getting text into command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting text into command line
# 1  
Old 05-03-2010
Getting text into command line

I have an IP address in a text file and i want to use it to mount a network share.
The command i will use is
Code:
 mount -t cifs //ipaddress/share /mnt/share -o username =hiro

I just need to know how can get the IP address from the text file and into the command?
Many thanks, Hiro.
# 2  
Old 05-03-2010
Code:
 mount -t cifs //$(cat IP_file)/share /mnt/share -o username =hiro

# 3  
Old 05-03-2010
Assuming the text file contains only one line with the ip address, following should work:
Code:
$ ip=$(awk '{print $1}' textfile)
$ mount -t cifs //$ip/share ...

# 4  
Old 05-03-2010
Thanks for the quick replies, anbu23, that just dumped the mount help file on the screen the way it does when it doesn't understand the syntax so there is not much i can tell you about why it doesn't work. There does not seem to be a verbose option for mount?

Psuedocoder, that throws a syntax error like this:

Code:
awk: (print $1)
awk: ^ syntax error
awk: cmd. line:1: (print $1)
awk: cmd. Line:1: ^unexpected newline or end of string

I put the line "echo $ip" after the first line which i think should have printed the ip address in the terminal? Or should it be "echo ip"? But it never got that far anyway i think.
As you can probably tell by new i am very new at this scripting game, in fact this is my first ever. I have managed to get all the way through to this last stage with only tutorials but have fallen at the last fence and just cannot do this part alone so any more ideas from you guys gratefully received
# 5  
Old 05-03-2010
Quote:
Originally Posted by hiro
that just dumped the mount help file on the screen the way it does when it doesn't understand the syntax
You get this error most likely because there is a whitespace between "username" and "=hiro".

Quote:
Originally Posted by hiro
Code:
awk: (print $1)
awk: ^ syntax error
awk: cmd. line:1: (print $1)
awk: cmd. Line:1: ^unexpected newline or end of string

You need to use curly brackets {} instead of ().

Quote:
Originally Posted by hiro
I put the line "echo $ip" after the first line which i think should have printed the ip address in the terminal?
Correct.
# 6  
Old 05-03-2010
I did have a space at the end there but after removing it there is no change, i will paste the exact line here for you to check for any other mistakes.

Code:
sudo mount -t cifs //$(cat /home/hiro/Documents/ipaddress)/music /mnt/music -o username=hiro

I changed to curly brackets in the other example, i assume you meant both pairs? and the lines are paster below again if you could see if i have done anything stupid there please.

Code:
ip=${awk '{print $1}' /home/hiro/Documents/ipaddress}
echo $ip
sudo mount -t cifs //$ip/music /mnt/music -o username=hiro

The error has changed with the bracket change, it is how.

Code:
./findip: line 10: ${awk '{print $1}' /home/hiro/Documents/ipaddress}: bad substitution

mount: wrong fs type, bad option, bad superblock on ///music,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

BTW i suppose i should add that i can mount the share by simply inserting the ip address in manually.
Thanks for the help so far, Hiro.
# 7  
Old 05-03-2010
We assumed that your command worked...
Can you successfully mount when you manually type the ip address? I guess no.
I checked the man page for mount and the flag "-o" as well as "username=xxx" seem to be unnecessary.

First try
Code:
sudo mount -t cifs //manually-type-ip-here/music /mnt/music

If it works, than you can try our suggestions.
Code:
$ ip=$(awk '{print $1}' /home/hiro/Documents/ipaddress)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. I am fetching object files from a library file, I have all the object file... (2 Replies)
Discussion started by: Paul Martins
2 Replies

2. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

3. Shell Programming and Scripting

Run a command on each line of a text file

Say I have a text file, with several lines. Each line may contain spaces or the # symbol. For each line, I want to pass that line as the path of a file, in order to add it to a tar file. I've tried this but doesn't work: cat contents.txt | xargs -0 `tar -uvf contents.tar $1`Any ideas? ... (3 Replies)
Discussion started by: Tribe
3 Replies

4. Shell Programming and Scripting

Command line: add text wrapper around words

I am trying to build a sinkhole for BIND. I created a master zone file for malicious domains and created a separate conf file, but I am stuck. I have a list of known bd domains that is updated nightly. The file simply contains the list of domains, one on each line: Bad.com Bad2.com... (4 Replies)
Discussion started by: uuallan
4 Replies

5. Shell Programming and Scripting

Replacing text in Perl given by command line

Hi I need to write a Perl script that the file given as first argument of the command line that will find all occurrences of the string given as the third argument of the command line and replace with the string given as the fourth argument. Name newfound file is specified as the second... (3 Replies)
Discussion started by: nekoj
3 Replies

6. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

7. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

8. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

9. Shell Programming and Scripting

Using ARGV, acepting text from command line

I want to be able to call in my file and make it do it's magic by basically giving it: FileNAME.pl searchTerm fileToSearch It runs, and gives me the answers I want, however, it gives me an error: Can't open GAATTC: No such file or directory at .//restriction_map_better.pl line 15... (2 Replies)
Discussion started by: silkiechicken
2 Replies

10. UNIX for Dummies Questions & Answers

replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually? -thanks;) (1 Reply)
Discussion started by: dudboy
1 Replies
Login or Register to Ask a Question