Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

can anyone knows how to reboot computer in just one line code of bash (by looping itself). The details will be get from the text file which are the IP Address of each computer. When the script gets the IP address of the computer it will go in and reboot it. HOw can I do it.

share|improve this question

1 Answer 1

Option 1# Using for loop

for host in $(< inputfile.txt );
do 

    ssh $host shutdown -r now 

done

Option 2# Using xargs

xargs -n1 -I{} echo ssh {} shutdown -r now  < inputfile.txt

Note: You need SSH Password less login or it will ask password for each host which is listed in inputfile

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.