Results 1 to 16 of 16

Thread: Batch files...

  1. #1
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Batch files...

    Remember them?

    I have a need to use one, possibly.

    The scenario is, we have a file which gets grabbed from an FTP site and put in a certain folder, which we need to decrypt using a Command Line script. Simple, you would think. But no, the file name changes every day, and need to be saved to another location with the same file name, minus the .crypt extension. Is there a way of querying the folder, obtaining the file name, then adding that file name into a command in order to decrypt the file, then move the decrypted file to one folder, and the original file to another?

  2. #2
    root Member DanceswithUnix's Avatar
    Join Date
    Jan 2006
    Location
    In the middle of a core dump
    Posts
    13,010
    Thanks
    781
    Thanked
    1,568 times in 1,325 posts
    • DanceswithUnix's system
      • Motherboard:
      • Asus X470-PRO
      • CPU:
      • 5900X
      • Memory:
      • 32GB 3200MHz ECC
      • Storage:
      • 2TB Linux, 2TB Games (Win 10)
      • Graphics card(s):
      • Asus Strix RX Vega 56
      • PSU:
      • 650W Corsair TX
      • Case:
      • Antec 300
      • Operating System:
      • Fedora 39 + Win 10 Pro 64 (yuk)
      • Monitor(s):
      • Benq XL2730Z 1440p + Iiyama 27" 1440p
      • Internet:
      • Zen 900Mb/900Mb (CityFibre FttP)

    Re: Batch files...

    Give up on batch files now, will save time in the short run let alone the long run.

    If you aren't a programmer, then write the script in Python. You should be able to use the curl library to talk to the ftp site to get a directory listing and grab the file to a temp directory, and then run the decrypter. As a plus side, the result should run on any operating system.

    A quick google for "python curl ftp directory example" got me some code to start you off:

    http://programming-tidbits.blogspot....directory.html


    Edit: Personally I would use Ruby, but I think Python is easier to get started in and it is a useful skill.
    Last edited by DanceswithUnix; 01-02-2018 at 10:43 AM.

  3. Received thanks from:

    Smudger (01-02-2018)

  4. #3
    Banhammer in peace PeterB kalniel's Avatar
    Join Date
    Aug 2005
    Posts
    31,039
    Thanks
    1,880
    Thanked
    3,379 times in 2,716 posts
    • kalniel's system
      • Motherboard:
      • Gigabyte Z390 Aorus Ultra
      • CPU:
      • Intel i9 9900k
      • Memory:
      • 32GB DDR4 3200 CL16
      • Storage:
      • 1TB Samsung 970Evo+ NVMe
      • Graphics card(s):
      • nVidia GTX 1060 6GB
      • PSU:
      • Seasonic 600W
      • Case:
      • Cooler Master HAF 912
      • Operating System:
      • Win 10 Pro x64
      • Monitor(s):
      • Dell S2721DGF
      • Internet:
      • rubbish

    Re: Batch files...

    Which operating system?

  5. #4
    mush-mushroom b0redom's Avatar
    Join Date
    Oct 2005
    Location
    Middlesex
    Posts
    3,510
    Thanks
    201
    Thanked
    388 times in 294 posts
    • b0redom's system
      • Motherboard:
      • Some iMac thingy
      • CPU:
      • 3.4Ghz Quad Core i7
      • Memory:
      • 24GB
      • Storage:
      • 3TB Fusion Drive
      • Graphics card(s):
      • nViidia GTX 680MX
      • PSU:
      • Some iMac thingy
      • Case:
      • Late 2012 pointlessly thin iMac enclosure
      • Operating System:
      • OSX 10.8 / Win 7 Pro
      • Monitor(s):
      • Dell 2713H
      • Internet:
      • Be+

    Re: Batch files...

    Well, given OP was asking about a batch file, I'm guessing Windows..... You could use powershell for this.

  6. #5
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    It is indeed Windows.

    Thanks, DwU, I'll take a look. The file is already extracted from FTP and dumped in a directory on the server, so that should save a few steps.

  7. #6
    root Member DanceswithUnix's Avatar
    Join Date
    Jan 2006
    Location
    In the middle of a core dump
    Posts
    13,010
    Thanks
    781
    Thanked
    1,568 times in 1,325 posts
    • DanceswithUnix's system
      • Motherboard:
      • Asus X470-PRO
      • CPU:
      • 5900X
      • Memory:
      • 32GB 3200MHz ECC
      • Storage:
      • 2TB Linux, 2TB Games (Win 10)
      • Graphics card(s):
      • Asus Strix RX Vega 56
      • PSU:
      • 650W Corsair TX
      • Case:
      • Antec 300
      • Operating System:
      • Fedora 39 + Win 10 Pro 64 (yuk)
      • Monitor(s):
      • Benq XL2730Z 1440p + Iiyama 27" 1440p
      • Internet:
      • Zen 900Mb/900Mb (CityFibre FttP)

    Re: Batch files...

    After a quick play, it sounds like this would be a starting point. Feeds all *.crypt files in the current directory through a command called "somedecrypter" specifying the output file name by stripping the .crypt extension off the source file and plugging .out on the end.

    I am not a Python programmer, but I can Google and hack something up
    Tested on Linux.

    Code:
    #!/usr/bin/python
    
    import glob, os
    
    for fileName in glob.glob( '*.crypt' ):
        fileBase = os.path.splitext( fileName )[0]
        os.system( "somedecrypter --in " + fileName + " --out " + fileBase + ".out" )

  8. Received thanks from:

    Smudger (01-02-2018)

  9. #7
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,232
    Thanked
    2,290 times in 1,873 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Batch files...

    Quote Originally Posted by Smudger View Post
    ... Simple, you would think. But no, the file name changes every day, and need to be saved to another location with the same file name, minus the .crypt extension. ...
    That sounds like a recipe for something to go horribly wrong at some point. My first step would be to examine the entire process and see if it can be streamlined. Why does the filename change? What creates the file in the first place? Why does it have to be put in a particular folder? Why are you using a file format that has to be processed on the command line? etc.

    At the minute it sounds like there's half a process in place, and you're adding another half a process, on ther assumption that gluing two half-processes together will give you a whole process. If the first half the process is out of your control completely then you'll have to work from the mid-point, but it's always worth examining the whole flow to see if any steps can be combined or, ideally, removed to streamline things...

    EDIT: and, as b0redom mentioned, Powershell would be the Windows way to do this

  10. Received thanks from:

    Smudger (01-02-2018)

  11. #8
    root Member DanceswithUnix's Avatar
    Join Date
    Jan 2006
    Location
    In the middle of a core dump
    Posts
    13,010
    Thanks
    781
    Thanked
    1,568 times in 1,325 posts
    • DanceswithUnix's system
      • Motherboard:
      • Asus X470-PRO
      • CPU:
      • 5900X
      • Memory:
      • 32GB 3200MHz ECC
      • Storage:
      • 2TB Linux, 2TB Games (Win 10)
      • Graphics card(s):
      • Asus Strix RX Vega 56
      • PSU:
      • 650W Corsair TX
      • Case:
      • Antec 300
      • Operating System:
      • Fedora 39 + Win 10 Pro 64 (yuk)
      • Monitor(s):
      • Benq XL2730Z 1440p + Iiyama 27" 1440p
      • Internet:
      • Zen 900Mb/900Mb (CityFibre FttP)

    Re: Batch files...

    Quote Originally Posted by scaryjim View Post
    EDIT: and, as b0redom mentioned, Powershell would be the Windows way to do this
    ... locking you into doing with 8GB or ram and a 6 core Xeon what you should be able to accomplish easily on a Raspberry Pi

  12. #9
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    Quote Originally Posted by scaryjim View Post
    That sounds like a recipe for something to go horribly wrong at some point. My first step would be to examine the entire process and see if it can be streamlined. Why does the filename change? What creates the file in the first place? Why does it have to be put in a particular folder? Why are you using a file format that has to be processed on the command line? etc.

    At the minute it sounds like there's half a process in place, and you're adding another half a process, on ther assumption that gluing two half-processes together will give you a whole process. If the first half the process is out of your control completely then you'll have to work from the mid-point, but it's always worth examining the whole flow to see if any steps can be combined or, ideally, removed to streamline things...

    EDIT: and, as b0redom mentioned, Powershell would be the Windows way to do this
    The file comes from an external company, so we don;t have control over the filename, unfortunately, so we are indeed starting from the midpoint.

  13. #10
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    Well, I did it in Powershell, and it works! Thanks all for the help, but now it fails when I run it as a scheduled task. Back to the drawing board.

  14. #11
    don't stock motherhoods
    Join Date
    Jun 2005
    Posts
    1,298
    Thanks
    807
    Thanked
    125 times in 108 posts
    • Millennium's system
      • Motherboard:
      • MSI X470 Gaming Plus
      • CPU:
      • AMD 3600x @ 3.85 with Turbo
      • Memory:
      • 4*G-Skill Samsung B 3200 14T 1T
      • Storage:
      • WD850 and OEM961 1TB, 1.5TB SSD SATA, 4TB Storage, Ext.
      • Graphics card(s):
      • 3070 FE HHR NVidia (Mining Over)
      • PSU:
      • ToughPouwer 1kw (thinking of an upgrade to 600w)
      • Case:
      • Fractal Design Define S
      • Operating System:
      • Windows 101 Home 64bit
      • Monitor(s):
      • HiSense 55" TV 4k 8bit BT709 18:10
      • Internet:
      • Vodafone 12 / month, high contentions weekends 2, phone backup.

    Re: Batch files...

    Please post the script out of interest? If it's not sensitive. I want to understand Powershell better.
    hexus trust : n(baby):n(lover):n(sky)|>P(Name)>>nopes

    Be Careful on the Internet! I ran and tackled a drive by mining attack today. It's not designed to do anything than provide fake texts (say!)

  15. #12
    Senior Member AGTDenton's Avatar
    Join Date
    Jun 2009
    Location
    Bracknell
    Posts
    2,840
    Thanks
    1,067
    Thanked
    886 times in 580 posts
    • AGTDenton's system
      • Motherboard:
      • MSI MEG X570S ACE MAX
      • CPU:
      • AMD 5950x
      • Memory:
      • 64GB Corsair something or the other
      • Storage:
      • 1x 512GB nvme, 1x 2TB nvme, 2x 8TB HDD
      • Graphics card(s):
      • ASUS 3080 Ti TuF
      • PSU:
      • Corsair RM850x
      • Case:
      • Fractal Design Torrent White
      • Operating System:
      • 11 Pro x64
      • Internet:
      • Fibre

    Re: Batch files...

    Quote Originally Posted by Smudger View Post
    Well, I did it in Powershell, and it works! Thanks all for the help, but now it fails when I run it as a scheduled task. Back to the drawing board.
    If possible consider running a Windows cron job over a Windows Scheduled Task... We've found it to be far more reliable.

  16. Received thanks from:

    Smudger (02-02-2018)

  17. #13
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    Quote Originally Posted by Millennium View Post
    Please post the script out of interest? If it's not sensitive. I want to understand Powershell better.
    Here you go, this was messing around to get it to work on my PC before transferring to live...

    $name = Get-Item c:\Data\File\*.crypt | Select-Object -ExpandProperty Basename

    .\openssl cms -decrypt -inkey "C:\Data\key.pem" -recip "C:\Data\cert.pem" -inform DER -in "c:\data\File\$name.crypt" -out "c:\data\File\$name"

    Move-Item -Path 'c:\data\file\*.xml' -Destination '\\destserver\share\'

    Remove-Item -Path 'c:\data\file\*.crypt'

  18. Received thanks from:

    Millennium (02-02-2018)

  19. #14
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    Quote Originally Posted by AGTDenton View Post
    If possible consider running a Windows cron job over a Windows Scheduled Task... We've found it to be far more reliable.
    Thanks for the advice, kind of thinking that it's working now, so we'll leave it using scheduled tasks, but will consider Cron if things go awry...

  20. #15
    root Member DanceswithUnix's Avatar
    Join Date
    Jan 2006
    Location
    In the middle of a core dump
    Posts
    13,010
    Thanks
    781
    Thanked
    1,568 times in 1,325 posts
    • DanceswithUnix's system
      • Motherboard:
      • Asus X470-PRO
      • CPU:
      • 5900X
      • Memory:
      • 32GB 3200MHz ECC
      • Storage:
      • 2TB Linux, 2TB Games (Win 10)
      • Graphics card(s):
      • Asus Strix RX Vega 56
      • PSU:
      • 650W Corsair TX
      • Case:
      • Antec 300
      • Operating System:
      • Fedora 39 + Win 10 Pro 64 (yuk)
      • Monitor(s):
      • Benq XL2730Z 1440p + Iiyama 27" 1440p
      • Internet:
      • Zen 900Mb/900Mb (CityFibre FttP)

    Re: Batch files...

    Quote Originally Posted by Smudger View Post
    Here you go, this was messing around to get it to work on my PC before transferring to live...
    Note that the Python script I posted deals with more than one *.crypt file in the directory so if the job failed to run for some reason it should cope with a backlog of files.

    Corner cases that shouldn't be possible often come back and bite you. What if there is one *.crypt file when the script starts running, but at the end a new one has turned up? Your powershell script will potentially delete an unprocessed file. Probably won't ever happen, but just a thought if the files start coming in more rapidly for some reason.

  21. Received thanks from:

    Smudger (02-02-2018)

  22. #16
    Senior Member Smudger's Avatar
    Join Date
    Oct 2005
    Location
    St Albans
    Posts
    3,873
    Thanks
    681
    Thanked
    620 times in 452 posts
    • Smudger's system
      • Motherboard:
      • Gbyte GA-970A-UD3P
      • CPU:
      • AMD FX8320 Black Edition
      • Memory:
      • 16GB 2x8G CML16GX3M2A1600C10
      • Storage:
      • 1x240Gb Corsair M500, 2TB TOSHIBA DT01ACA200
      • Graphics card(s):
      • XFX Radeon HD4890 1GB
      • PSU:
      • Corsair HX520
      • Case:
      • Akasa Zen
      • Operating System:
      • Windows 10 Home
      • Monitor(s):
      • Dell 24"
      • Internet:
      • Virgin 200Mbit

    Re: Batch files...

    Quote Originally Posted by DanceswithUnix View Post
    Note that the Python script I posted deals with more than one *.crypt file in the directory so if the job failed to run for some reason it should cope with a backlog of files.

    Corner cases that shouldn't be possible often come back and bite you. What if there is one *.crypt file when the script starts running, but at the end a new one has turned up? Your powershell script will potentially delete an unprocessed file. Probably won't ever happen, but just a thought if the files start coming in more rapidly for some reason.
    Actually, the act of decrypting deletes the /crypt file anyway, so I've remove that line.

    By all accounts, the delivery of this file is going to be sporadic, so it's a case of 'do what you can with the tools you've got, without spending too much time on it'... We'll look more deeply into it, I think, if it becomes a big thing...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •