How do I get system_profiler output from a lot of machines in a network? I need to have a script that will execute "system_profiler -detailLevel full" command in a remote mac machine. While this is going on, the user on the remote machine should not know that there is something happening. 

I tried the following applescript:

tell application "Terminal" of machine "eppc://&lt;ip address of remote machine&gt;"
    activate
    do script "system_profiler -detailLevel full &gt;&gt; /$HOSTNAME.txt" 
end tell


This activates the terminal app on the desktop and hence a bad idea, as user working on that remote machine is interrupted. I want this to happen in the background.

I want a shell script (not an applescript) that will take the name of hostnames from a text file stored on the same location where the shell script is. It will then go to each host from that list of hostnames, execute the system_profiler command and copy the text file having the output of the command ($HOSTNAME.txt file) back to the machine from where the shell script was executed.

The file copying should be done without ssh,scp etc.
For reading a text file of hostnames into an AppleScript list, see Read textfile into list in Applescript.

For looping over hostnames within your AppleScript list see An AppleScript list iterate/loop example:

set myList to {"Hello", "Goodbye", "I must be going"}
repeat with theItem in myList
  say theItem
end repeat


do shell script

To avoid launching Terminal.app, use the do shell script command:

tell machine "eppc://&lt;ip address of remote machine&gt;"
    do shell script "system_profiler -detailLevel full &gt; /tmp/sysprofile.txt"
end tell


This can be run without launching a supporting graphical application.

I am assuming you can not access the remote host via secure shell, only via Remote AppleEvent access eppc.

Returning the File

Read the contents of the file within your AppleScript's tell machine block and save it locally outside of the tell machine block.

Alternatively, have you considered transferring back the system profile file via ssh or scp? Consider having your AppleScript to connect to your Mac and copy back the collected system profile.