LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2018, 12:44 AM   #1
Nyikodem
LQ Newbie
 
Registered: Jan 2018
Posts: 3

Rep: Reputation: Disabled
Macro under Linux


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?

Thank you in advance.

Nyikodem
 
Old 01-24-2018, 01:24 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
looks like expect can do that for you, but your "specification" is a bit ambiguous.
 
Old 01-24-2018, 02:17 AM   #3
Nyikodem
LQ Newbie
 
Registered: Jan 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello,

Thank you for your answer.

I am asking an advise...

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.

Thank you in advance,

NYikodem
 
Old 01-24-2018, 02:44 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
Old 01-24-2018, 04:07 AM   #5
Nyikodem
LQ Newbie
 
Registered: Jan 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi,

Thank you for your answer.
I am going to try it.

Best regards,

Nyikodem
 
Old 01-24-2018, 08:02 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 01-24-2018, 08:10 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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
}
 
Old 01-24-2018, 08:19 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
yes, it is even better - if you don't want to take care about possible responses.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What is the point of using the linux macro access_ok() wcrandthor Linux - Kernel 2 09-10-2012 02:33 PM
Macro software for Linux? nyheat Linux - Software 4 03-18-2008 11:59 AM
about CP_UTF8 macro on Windows/Linux George2 Programming 9 05-04-2006 05:30 PM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM
Is there a good macro recorder in linux? Bad_Bob Linux - Software 6 06-22-2004 08:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration