A very small and very useful IBM AIX command
??????Andrey Klyachkin
#1 in Automating IBM Power and IBM AIX Infrastructure | POWER DevOps | IT Infrastructure Automation | Speaker | Trainer | Author | IBM Champion | IBM AIX Community Advocate
I had a task - remove ca. 200 volumes from a storage device. The storage device was developed by a famous IBM competitor, which was bought by a famous server vendor several years ago. Since that time the support of the box develops in one direction only - worse every year. After last firmware update command line interface didn't work anymore. The engineer who did the update told, that he already finished the update and logged off from the system, so he can't fix anything. We opened a case at the vendor and the support engineer wrote, that the web interface works, that's why he doesn't see any problem why command line shouldn't work. Anyway we solved the problem and in a month or two the box will be empty and completely migrated to a new IBM Flash Systems.
So I have to delete ca. 200 volumes from the box. Of course, I can use the web interface, as it proposed by the aforementioned support engineer, and click me 200 volumes there and then choose delete button. If I have luck, I will click exactly the volumes I want to delete. Otherwise I'd delete some 'still in production' volumes.
That's why my way is to use command line. Fortunately I can login to the box using ssh and issue the command:
remove-volume vol-id="volume1"
Because I have a list of volumes like:
volume1
volume2
volume3
I can even generate commands for me:
$ sed 's/^\(.*\)$/remove-volume vol-id="\1\"/' list
remove-volume vol-id="volume1"
remove-volume vol-id="volume2"
remove-volume vol-id="volume3"
Because I'm lazy as every "normal" system administrator in the world, I don't even want to open a ssh session on my own and can add ssh to the line:
$ sed 's/^\(.*\)$/ssh user@storage '\''remove-volume vol-id="\1\"'\''/' list
ssh user@storage 'remove-volume vol-id="volume1"'
ssh user@storage 'remove-volume vol-id="volume2"'
ssh user@storage 'remove-volume vol-id="volume3"'
Here it is! I'm almost happy! I pipe everything through shell and watch how 200 volumes are being removed:
$ sed 's/^\(.*\)$/ssh user@storage '\''remove-volume vol-id="\1\"'\''/' list | sh
Unfortunately, not really. The guys, who designed the command line interface, wanted to be sure, that I don't occasionally delete some volumes. Everytime the command is executed I have to type 'yes' manually.
Are you sure? Yes!
Are you really sure? Yes!
领英推荐
Are you really-really sure? Yes! Yes! Yes!
OK, I am a UNIX guy and UNIX has a solution for every possible problem. Someone before me was already bothered by such fine interfaces and wrote a wonderful utility, which is called (you know!) - yes.
If you start the tool (just write yes in your console), you get an endless number of 'yes'-lines on your screen (on AIX, Linux may behave differently). This is exactly the only task which the tool does - it sends as many "yes" to standard output device as you want. Using the tool and standard UNIX pipe capability, the problem is solved:
$ yes | ssh user@storage 'remove-volume vol-id="volume1"'
Everytime the storage box asks for a confirmation, it automatically gets yes from my AIX box.
What if I am not so sure and would like to answer no? The command "no" exists on AIX, but does something different. It sets network options (no) or tunables. It may sound funny, but you should enter 'yes no' in this case:
yes no
and you get an endless number of 'no' on your screen. Of course you can write everything you want after the command. Let's say, if you're preparing for Christmas, you may write:
yes 'Merry Christmas'
or even:
yes 'Have fun!^JAndrey'
To enter '^J' you use Control-V and then Control-J on your keyboard, if you are in vi mode.
Have fun!
Andrey
P.S. I deleted all the volumes and because there were no incidents in the queue, I suppose I deleted the right volumes.
Senior IT Managing Consultant, IBM Power Systems Lead - IBM Platinum Redbooks Author
2 年sed/awk are always helpful.
Technical Solution Architect, Enterprise Architect, Field CTO, Technical Sales Advisor, Master Consultant, Adjunct Instructor | Data center compute, storage, automation, modernization, HPC, AI | 7x IBM Champion 2019-2025
2 年One of my favorite commands.