diff --git a/mvs_job.py b/mvs_job.py index d7281e1..cce3eb0 100755 --- a/mvs_job.py +++ b/mvs_job.py @@ -16,14 +16,11 @@ MVSHOST = "oldcomputernerd.com" RDRPORT = 3505 MVS_PASSWORD = os.environ.get("MVS_BATCH_PASSWORD") -def upload_source(local_file, dataset_name, member_name, mvshost=MVSHOST): - """Upload source code to MVS PDS member""" - # Read the source file - # full path will come from the job runner - # filepath = os.path.join(SRCLIB, local_file) +def create_jcl_payload(local_file, dataset_name, member_name): + with open(local_file, 'r') as f: - source_lines = f.readlines() + sysin = f.readlines() # PDS member: Use IEBUPDTE jcl = f""" @@ -39,31 +36,48 @@ def upload_source(local_file, dataset_name, member_name, mvshost=MVSHOST): """ # Append control statement, source lines, end, and terminator (no leading space on ./) jcl += f"./ ADD NAME={member_name}\n" - for line in source_lines: + for line in sysin: line = line.rstrip('\n')[:80] jcl += line.ljust(80) + "\n" jcl += "./ ENDUP\n" jcl += "/*\n" - # Write JCL to temporary file and submit via netcat - with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.jcl') as tmpfile: - tmpfile.write(jcl) - tmpfile_path = tmpfile.name + return jcl + +def upload_source(local_file, dataset_name, member_name, mvshost=MVSHOST): + """Upload source code to MVS PDS member""" + + # Read the source file + # full path will come from the job runner + # filepath = os.path.join(SRCLIB, local_file) + payload = create_jcl_payload(local_file, dataset_name, member_name) + + # Write JCL to temporary file and submit via netcat + + with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.jcl') as tmpfile: + tmpfile.write(payload) + tmpfile.flush() + tmpfile_path = tmpfile.name try: - # Use cat to read the file and pipe to netcat - # cmd = f"cat {tmpfile_path} | nc -w3 {mvshost} {RDRPORT}" - cmd = f"nc -w 5 {mvshost} {RDRPORT} < {tmpfile_path}" - print(cmd) - subprocess.run(cmd, shell=True, check=True) + with open(tmpfile_path, 'rb') as f: + subprocess.run( + ['nc', '-w', '5', mvshost, str(RDRPORT)], + input=f.read(), + check=True, + capture_output=True + ) print(f"Uploaded {local_file} to {dataset_name}({member_name})") return 0 except subprocess.CalledProcessError as e: print(f"Upload failed: {e}") + print("stderr:", e.stderr.decode(errors='ignore')) return 1 + finally: - # Clean up temp file - os.unlink(tmpfile_path) + # Clean up outside + #os.unlink(tmpfile_path) + print(f"Would have deleted {tmpfile_path}") def submit_jcl(job, mvshost="oldcomputernerd.com"): """Submit JCL job from local directory""" diff --git a/tmp.py b/tmp.py new file mode 100644 index 0000000..76071c9 --- /dev/null +++ b/tmp.py @@ -0,0 +1,28 @@ + + # --------------------- DIAGNOSTICS: Prove temp file is created & readable --------------------- + print("\n--- TEMP FILE DIAGNOSTICS ---") + print(f"Current working directory: {os.getcwd()}") + print(f"Temp dir in use: {tempfile.tempdir}") + + if os.path.exists(jcl_path): # jcl_path is the variable holding your temp file name/path + print(f"File exists: YES → {jcl_path}") + print(f"File size: {os.path.getsize(jcl_path)} bytes") + + # Show basic permissions (octal, e.g. 0o644 = rw-r--r--) + st = os.stat(jcl_path) + print(f"Permissions (octal): {oct(st.st_mode & 0o777)}") + print(f"Owner UID: {st.st_uid} (your user should match os.getuid())") + + # Try reading it back to prove readability + try: + with open(jcl_path, 'r') as f: + content = f.read() + print("File is readable! First 200 chars of content:") + print(repr(content[:200])) # repr() shows escapes/newlines clearly + print(f"... (total lines: {content.count('\n') + 1})") + except Exception as e: + print(f"Read failed: {e}") + else: + print("File exists: NO → something went wrong creating it") + print("--- END DIAGNOSTICS ---\n") + diff --git a/tmp/tmpfawu192m.jcl b/tmp/tmpfawu192m.jcl new file mode 100644 index 0000000..a7904dd --- /dev/null +++ b/tmp/tmpfawu192m.jcl @@ -0,0 +1,60 @@ + +//UPLOAD JOB (ACCT),'UPLOAD', +// USER=@05054,PASSWORD=PASSWD, +// CLASS=A,MSGCLASS=H,NOTIFY=@05054 +//COPY EXEC PGM=IEBUPDTE,PARM=NEW +//SYSPRINT DD SYSOUT=* +//SYSUT1 DD DUMMY +//SYSUT2 DD DSN=@05054.SRCLIB.C,DISP=MOD,UNIT=SYSDA, +// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) +//SYSIN DD * +./ ADD NAME=SIEVE08 +#include + +#define LIMIT 10000 +#define PRIMES 1000 + + +int main() +{ + int i,j,numbers[LIMIT]; + int primes[PRIMES]; + + for (i=0;i + +#define LIMIT 10000 +#define PRIMES 1000 + + +int main() +{ + int i,j,numbers[LIMIT]; + int primes[PRIMES]; + + for (i=0;i