put script into file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers put script into file
# 1  
Old 11-18-2011
put script into file

hi, ok having here some code like:
PHP Code:
#!/bin/bash
echo " hello "          # say hello to the user
echo $HOME " 
echo $HOSTNAME "
echo " $(uname) "
echo " today is $(date) "
echo " $(whoami) is currently logged in  " 
now my question is how to change the code so that the info is not displayed but sent to a file ?

I know its a basic thing for you but I am just beginning here so looking forward for your response . .. . .
thanks
# 2  
Old 11-18-2011
Code:
(yourscript) > (output.file)

Since you know it was basic why did you not post your question in appropriate forum ?

There is a forum called for dummies you know, or is that offencing?
# 3  
Old 11-18-2011
if moderator thinks it should be moved to dumies forum he/she probably will move it....no not offended

but since we r here, can u change that code to not be displayed just put to file ?
# 4  
Old 11-18-2011
Moved...
Forum rules
(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.
# 5  
Old 11-18-2011
Quote:
can u change that code to not be displayed just put to file ?
Have you tested ?

Not wise to ask before having tested given solution...
# 6  
Old 11-18-2011
Quote:
Originally Posted by vbe
Have you tested ?

Not wise to ask before having tested given solution...
quick responses and actions Smilie vbe,

changed and it worked, thanks for that, but got follow up question...

code now looks like that

Quote:
#!/bin/bash
FILE=$1

if [ -f $FILE ];then

echo " hello " >> file # say hello to the user
echo " $HOME " >> file
echo " $HOSTNAME " >> file
echo " $(uname) " >> file
echo " today is $(date) " >> file
echo " $(whoami) is currently logged in " >> file

else
touch file

fi
and my question is can these code be changed so I don't have to type " >> " in every line?
# 7  
Old 11-18-2011
Look:
Code:
vi 006
i
#!/bin/bash
echo " hello "          # say hello to the user
echo " $HOME " 
echo " $HOSTNAME "
echo " $(uname) "
echo " today is $(date) "
echo " $(whoami) is currently logged in  "  
:wq
"006" [New file] 7 lines, 184 characters 
an12:/home/vbe $ chmod 750 006
an12:/home/vbe $ ./006 > 006.out
an12:/home/vbe $ more 006.out
 hello 
 /home/vbe 
 an12 
 AIX 
 today is Fri Nov 18 16:43:17 NFT 2011 
 vbe is currently logged in  
006.out: END

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

2. Shell Programming and Scripting

i writing a unix script but i want to out put a file and append on it.

i have an existing script that is used to send an e-mail containing the alrams that appear on the server. But i need to create a daily log file containing all the alarms that was send that day. i tired to add at the and of the script a command, echo command but for some reason the file was... (1 Reply)
Discussion started by: ashraf_victory
1 Replies

3. UNIX for Advanced & Expert Users

put data in excel file using shell script

Hi. I wish to add data in a specific excel file on daily basis.However the currect dat's data should always come on top i.e for example should always occupy cell A7,B7,C7 .. and the data of day before which was earlier on 7th row of each coloumn should move to 8th row..data on 8th row should... (1 Reply)
Discussion started by: kanus
1 Replies

4. Shell Programming and Scripting

Script to put block comment after finding regex in xml file

hi, i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment. so eg.. first block <filter> <filter-name>MyRegEx</filter-name> ... (11 Replies)
Discussion started by: Poki
11 Replies

5. Shell Programming and Scripting

how to put data using shell script to a excel file

Hi, Can any one tell me how to put data using shell script to a excel file from text file to other columns of excel file,leaving first column unaffected i.e it should not overwrite data in first column. Say my text file data is: 15-dec-2008 15-dec-2009 16-dec-2008 16-dec-2009 say my first... (1 Reply)
Discussion started by: siri_886
1 Replies

6. Shell Programming and Scripting

Could I put this into a case script instead?

Hi guys, I have a script which clears down a range of directories, however it can take a while to run. Is there a way I can simplify the below, perhaps adding it into a case statement? client_directories=/usr/local/production/cleanup/bin/client_cleanups/client_directories.txt # clear down... (2 Replies)
Discussion started by: JayC89
2 Replies

7. Shell Programming and Scripting

ftp put in shell script -- whole file doesn't upload

Hi I'm having some trouble with a bash shell script that I'm writing. In the script, I'm trying to upload a file to a backup repository using ftp, but the whole file doesn't get uploaded. This is the file's properties at the start (I've highlighted the file size in red): -rw-r--r-- 1 root... (2 Replies)
Discussion started by: Viola
2 Replies

8. UNIX for Dummies Questions & Answers

Where should I put the script?

Hi Guys, I'm a new to the UNIX. Let say I have a 1 simple script to stop and start vnc service. I want to use that script for support because my network connection to my client side is not stable and every time I have to use a long command to restart vnc. Where should I put that script?... (3 Replies)
Discussion started by: akuslive
3 Replies

9. Shell Programming and Scripting

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (2 Replies)
Discussion started by: shilendrajadon
2 Replies

10. UNIX for Advanced & Expert Users

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (1 Reply)
Discussion started by: shilendrajadon
1 Replies
Login or Register to Ask a Question