We help IT Professionals succeed at work.

pretty basic i think???

Mrdogkick
Mrdogkick asked
on
228 Views
Last Modified: 2010-04-21
Hello all,
I have written the following script to display currently logged in users and the processes they are using...I can't for the life of me figure out how to overwrite what is in 'myfile' rather than have the info added on to the file...I have played about with the >'s but to no avail...Any ideas?
#!/bin/bash
for user in `users`
do
  grep "^$user:" /etc/passwd | cut -d: -f5 >>myfile
  ps -fu $user >>myfile
  echo >>myfile
done
 
 
 
 
echo "Check myfile for output!!"
 
echo "Check myfile for output!!"
 
echo "Check myfile for output!!"
 
echo "Check myfile for output!!"
 
echo "Check myfile for output!!"

Open in new window

Comment
Watch Question

Good Ol' Geek
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
yeah, i have tried that but now myfile is blank...

Author

Commented:
this'll have to do...
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
If you also changed the echo >>myfile to echo >myfile
it would again overwrite myfile with the blank line that the echo produced
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.