1

I am a complete noob. I would like to create a shell script in centOS7 that does these 3 steps and I don't even know where to begin :

  1. Run somepythonscript.py in currently opened directory (folder) in terminal. (The python script will create .dat file called NCS.dat inside this directory)

  2. rename the file NCS.dat with name of the folder that is 2 levels above (so if the path to the file is FolderName1/FolderName2/NCS.dat I want the NCS.dat be renamed to FolderName1.dat)

  3. move the renamed .dat file to some other random folder X.

Hope I made it clear. Thank you in advance!

stovfl
  • 14,998
  • 7
  • 24
  • 51
Saudruch
  • 13
  • 2
  • 1
    Welcome to SO. Please provide a Minimal, Complete, and Verifiable example. **Show us the code for your latest attempt** and where you got stuck. and explain why the result is not what you expected. Edit your question to include the code, please don't add it in a comment, as it will probably be unreadable. https://stackoverflow.com/help/mcve – Dragonthoughts Sep 05 '18 at 12:27

2 Answers2

0

You should be able to run the python file using the python run command. For example,

>> python runsomepyfile.py <ARGS>

To get python to read from a specific directory you can use os module to set your path and run operations from there.

See: How to know/change current directory in Python shell?

kmjb
  • 164
  • 9
0

Try this

python somescript.py 
var=$(cd .. && cd .. &&  basename "${PWD}")
mv NCS.dat $var.dat
mv $var.dat /someotherpath/$var.dat
Albin Paul
  • 3,330
  • 2
  • 14
  • 30