Reverse prior batch job (without simply rewriting the script)


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Reverse prior batch job (without simply rewriting the script)
# 1  
Old 09-03-2019
Reverse prior batch job (without simply rewriting the script)

So, let's say I have a usual batch rename file like this:

Quote:
move hello 254352426
move farewell 464473525
move 13fads 57655625635
move watswas jr3ogh39uh39
and I'd like to have a secon bat file, that can /reverse" the first.

BUT, I don't want to simply "rewrite" it like
Code:
move hello 254352426

but rather, have the new script take the source and destination and reverse it somehow like this:

move "var1" "var2"

Is this possible ?

- pasc
# 2  
Old 09-04-2019
It may be not that simple, to reverse a script.

For example, if you have a file consisting of a and b characters. Your normal script replaces a with b. How do you reverse that? It's not possible to know original a's had been.

That maybe possible or impossible depending on the specific task. But there's hardly a generic way to do this.

If the task is about manipulating files you may take a backup before the task via cp, tar, rsync, ... and reset the state to that backup when needed.

What are you about to do? Why do want to reverse an action? What exactly do you want to reverse?

And of course: What's your OS environment and programming language/shell?

Last edited by stomp; 09-05-2019 at 03:09 AM..
# 3  
Old 09-05-2019
What are you about to do? Why do want to reverse an action?


Simple:


I want to have a second script that is not simply a "line by line reverse copy" of the first script,
but rather something that reads from the first.
=> So I don't have to have update two scripts.




Example:
Quote:

You have a program a that outputs folders in the following order:
11111112a
111111123b
111111124c
and these folders cannot be read by program b
That program requires the names to be:


aaaaaaaab1
aaaaaaaabc2
aaaaaaaabd3


You write a script that does:
move 11111112a aaaaaaaab1
...


so it will work with program b.
However then program a (that originally outputted the data)
can nolonger access the data.


=> You'd have to maintain "move filenames to program-b.bat" and "move-filenames-to-program-a.bat"
A real hassle, cause you have to update both scripts with each new entry, and if you forget just a single line along the way the corresponding script is worthless until you go error hunting.
TL;DR:
I want to have a script that parses another script and does the job in another order.
# 4  
Old 09-05-2019
Code:
I want to have a script that parses another script and does the job in another order.

I would not say this isn't possible, but extremely complex to parse any scripting language or shell. I wouldn't ever dare to start such a program even having 20+ years of experience in scripting.

You need to have the skill level of a compiler/interpreter developer. Definitively not a practical way to go.

An option i got to know of are snaphotting tools: Run some programm. Look what it did(changed files, permissions,...) and undo the effects made.

Besides: We're at unix.com here. I doubt that you find much ms windows expertise here.

Last edited by stomp; 09-05-2019 at 11:03 AM..
# 5  
Old 09-05-2019
It may be as simple as

Code:
awk '{print $1, $3, $2}' file

and pipe the result into sh. Be aware that when "automating" things you should know exactly what you are doing , and do a test run before each "live" run...
# 6  
Old 09-07-2019
Quote:
Originally Posted by stomp
Code:
I want to have a script that parses another script and does the job in another order.

I would not say this isn't possible, but extremely complex to parse any scripting language or shell. I wouldn't ever dare to start such a program even having 20+ years of experience in scripting.

You need to have the skill level of a compiler/interpreter developer. Definitively not a practical way to go.

Thats what I sadly figured, but asking is free of charge as they say Smilie




Quote:
Originally Posted by RudiC
It may be as simple as

Code:
awk '{print $1, $3, $2}' file

and pipe the result into sh. Be aware that when "automating" things you should know exactly what you are doing , and do a test run before each "live" run...

That looks interesting, sadly I'd have to run this via windows utitlites (awk might exist, but it isn't stock inventory).


The good news for my script is that the



"move" "parameter 1" "parameter2"


are certainly constant. Also they are all seperated by one " " space and each line is build that way.


If it was possible to move -one line at a time- and use these parameters" that way.. hmm..
# 7  
Old 09-07-2019
If your original scripts are that simple, I would be surprised if there's no possibility to do it.

Those techs (stock windows) will probably enable you to script a solution:

Visual Basic Script
Powershell
Windows Script Host
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

To run job in parallel in batch

Hi, I am using a batch file to run 2 or more shutdown batch for each of my server like below: Shutdown_serverA.bat Shutdown_serverB.bat ... Is there anyway i can do this in parallel instead of serially:confused: ServerA & ServerB shutdown at the same time in one click (batch). (4 Replies)
Discussion started by: beginningDBA
4 Replies

2. Solaris

Can a batch job truly have a PID of 1?

Is it possible for a process id of 1. Is there anything special about 1 or 8 ? (7 Replies)
Discussion started by: Harleyrci
7 Replies

3. UNIX for Dummies Questions & Answers

How to create a batch job ?

Hi In unix how to create a batch job and Is there any command to close file in unix. Please help me I am new to unix world (6 Replies)
Discussion started by: vinay.h4
6 Replies

4. AIX

Script to start a remote batch job on another server

Hi , I am trying to execute one script residing on server B from server A and in automated way but with a trigger. My main quetion are 1) How I will login to the remote server automatically with user name and password. ( rsh or any other way ?) 2) Once logged in I need to execute... (2 Replies)
Discussion started by: agent47
2 Replies

5. Shell Programming and Scripting

Help rewriting my KSH-script...

Hi! I'm a beginner at scripting, but have managed to complete a working KSH-script.. :D But since this is going to production i a few weeks, I would like to optimize it and make it better structured! The idéa of the script is to collect data from the database, put it in a file, and then... (2 Replies)
Discussion started by: linsto
2 Replies

6. Shell Programming and Scripting

A Batch job to delete files from various directories

Hi, I have a shell script to find files older than 'X' days ($2) in directory path ($1) and delete them. Like this: my_file_remover.sh /usr/home/c 90 Now, I need to modify this script and add it in CRON, so that it checks other directories also. Like: my_file_remover.sh /usr/home/c... (3 Replies)
Discussion started by: guruparan18
3 Replies

7. UNIX for Dummies Questions & Answers

Regarding interactive ID of batch job

Hi all, We are running a batch job using Unix script. This batch job is running daily to get data from a Mainframe database and to load our tables. We are using an interactive ID for the batch job. If we removed that interactive ID, the batch job fails. What's my question is.. Is the... (1 Reply)
Discussion started by: pradeep.edara
1 Replies

8. Shell Programming and Scripting

read input file for batch job

hi all, I am a newbie in unix shell script. May I know how to write a bacth job to read a list of files afrom the inout file and do the chmod ? Thanks. i.e. inside input.txt ==== a.txt b.txt c.txt and I want to write a batch job to read the input .txt and do the chmod 755 for all 3... (14 Replies)
Discussion started by: kinmak
14 Replies

9. Windows & DOS: Issues & Discussions

windows scripting for a batch job

I have been doing unix scripting for quite awhile and there seems to be a wealth of information on it. Now I am working on migrating an intel based application to a new server. I need to modify some existing scripts, but am having trouble finding information on windows scripting, a forum similar... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question