ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I write a macro under linux? The system is Centos 6.x on an Intel server. I use this linux from remote via Teraterm. There is a character based program on the server let us called "PP". I would like to write a macro that drives PP. This macro has to - start PP - sends key hits like up, down, enter, F3, and characters to PP - and I would like to manipulate files on the server meanwhile the operation runs as well
I tried to use cpability of Teraterm, but it runs on windows PC remotely and I could not manipulate files on the server meanwhile.
How can I do it? Is there any language which can be used? Macro recording with editing of recorded macro? Is there a solution already progrmmed with an IDE?
I would like to write a script or a macro but I do not how or in which language or in which solution . I have some programming and Linux knowledge but I do not know how can I start to solve this problem.
I started to write a Teraterm script (it sends key hits up, down "O", "K" leters etc..) and it is working but there are some problems with it eg: this script is running on my laptop adn Teraterm and the script manages the PP on the remote server, but there is no feedback about the results. Second problem is that I would like to manipulate some files on the server meanwhile runnig this script. Teraterm scripting language is not able to support these needs.
This is why I would like write a macro or a script which is similar to the mentioned above with extended other possibilities runnig on the server ability to do simulating key hits and manipulation of files same time.
I saw that tere are macro recording softwares, but the recorded format is to diffiult for me to edit (extend with file manipulation) and understand.
I also saw some python command like keystroke('CTRL+F4'), but I do not familiar with python (does it have IDE anyway, etc..). What do you think python could be good for this reason?
So I am looking for a simple way to solve my problem. I am asking an advise, I do not want anybody to write the solution instead of me.
expect is a tool and my advice is to try that (probably together with bash). You can start it with a single/simple step and extend later with additional steps.
There's actually a command line way to do this. Boy I'll have to search my archives. I once wrote scripts which created install disks and they made assumptions that the target disk needed to be partitioned and formatted, after confirming the user entered their options correctly. The fdisk calls used bash notation to inject the commands into fdisk. Because interactively sitting there entering in 'n', '1', '<return>', '<return>' was not an option, unless you wanted the user to sit there and do all that, which then would have negated much of the need for a script, and also put the requirements back at the person to understand what partition types, etc were needed for that install disk.
I'll post a relevant chunk of that, providing I can locate that many years old work.
Ah, here we go. Note that these are functions which are part of scripts I wrote, and their intentions are stated in the comments, but also their intentions are to fully partition and format a flash card to prepare to make it a Linux system disk. So don't just grab them and use them, instead see what the notation does to inject the commands to the fdisk utility and see if they can help you with what you are doing. I long ago found out how to automatically inject commands, by doing a web search, resulting in this. Not sure if this will serve you, but perhaps it may:
Code:
# Function to delete all partitions
# that may be on the disk
delete_partitions()
{
cat<<EOF|sudo fdisk $1>&setup-disk.log
d
1
d
2
d
3
d
4
d
w
EOF
}
# Function to create desired partitions
# Partition #1 = 32M
# Partition #2 = Rest of disk
create_partitions()
{
cat<<EOF|sudo fdisk $1>&setup-disk.log
n
p
1
1
+32M
n
p
2
w
EOF
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.