LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2024, 06:14 AM   #1
mprowe
LQ Newbie
 
Registered: Mar 2024
Posts: 2

Rep: Reputation: 0
Angry Copy a file with mktemp as destination?


I'd like a one-line (that I can put in my crontab), something like this?

$ cp <sourcefile> <mktemp -p /sms sourcefile_XXXXXX>

Regards, Martin
 
Old 03-26-2024, 06:24 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,854

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
better to put it into a script and run that script from crontab.
Code:
 cp <sourcefile> $(mktemp -p /sms sourcefile_XXXXXX)
or something similar may work
 
1 members found this post helpful.
Old 03-26-2024, 06:35 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
You ought to wrap that in a script.

Code:
#!/bin/sh

PATH=/usr/local/bin:/usr/bin:/bin

set -e

p=sms
test -e /tmp/${p} || mkdir -p /tmp/${p}
test -d /tmp/${p}

dst=$(mktemp -p ${p} -d sourcefile_XXXXXX)
src=somesourcefile

cp -p ${src} ${dst}
As a one-liner it would still be using command substitution.

Code:
cp -p somesourcefile $(mktemp -p sms -d sourcefile_XXXXXX)
The way you have it set, the directory /tmp/sms/ must exist before running mktemp because mktemp won't create it for you.
 
  


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] mktemp problem with pass ("cannot create temp file /tmp/foo: Invalid argument") drgibbon Slackware 2 01-16-2017 09:32 PM
how does mktemp prevent denial-of-service attack seaker79 Linux - Security 1 04-22-2010 06:56 AM
mktemp: cannot create temp file at startkde windstory Linux - Newbie 1 10-14-2009 03:40 AM
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 04:37 PM
abt patch the Mktemp fengfeng Linux From Scratch 1 02-23-2008 12:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:17 AM.

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